❔ Assignment
Hi, pretty fresh to C# and im currently working on a assignment wich requires me to make a simple yet functional Inventory System utilizing interfaces, this is a console project, ive been stuck on this for the past few hours, currently my only issue would be how to turn a specific file into a public class so that i can mention it within the main file of the project.
These are the files i currently have:
IPanel.cs
Item.cs
17 Replies
ItemShop.cs, this is the file i want turned into a public class
Program.cs, this is the main file, i turned it into a comment so that it would not break the code due to the itemshop file
it seems like ur
Item
and IPanel
types are not in a namespace, u should not do that. put them in a fitting namespace like ur other classes
u can automatically access types in the same namespaces as if they would be written in the same file
if the namespaces are different, u can use the using <namespace>;
statement to import that namespace
and then all types of that namespace are directly accessible by its name
eg. if u have
u can use it somewhere else like this:
if Program
would have been also in MyNamespaceA
, or MyClass
also in MyNamespaceB
, u would not need the using
at all
another way would be to use the "full qualified name"
MyNamespaceA.MyClass instance = new MyNamespaceA.MyClass();
tho that is quite long as u can seethose didnt use namespaces cuz thats how i was given them
and from what ive been told i cant really alter that i think
although i could be wrong on that
it feels like ItemShop should be a class as well, not a namespace?
thats what i want to do
i want to turn ItemShop into its own class so that i can reference it within program.cs
well in case u are not allowed to alter their namespace, then just dont stuff
Program
into a namespace either
u do not have a ItemShop
class right now, just a namespace by that nameNot sure why you moved the Program class out of Program.cs then 🙂
what i want to do is change that, i want ItemShop to be a class while program.cs would be the only thing with a namespace
i didnt, i imported a file from a project i used before, i was gonna adapt that file to this project
if they are in the default namespace/no namespace, their full qualified name is just their name (i mean u r using them like that already in ur
Program
class)how would i get rid of the static void Main without fucking up everything tho? cuz every time i try to do that it jsut comepletely breaks everything
do u mean top level statements?
and
are basically the same
the first one will automatically be transformed into the second one under the hood
I think probably it's because Program/Main are in ItemShop.cs, where they don't want them to be, and not in Program.cs - which is fully commented out
so basically u could have the following
note that i made the
DoSomething
method public
here, private
stuff can only be accessed from inside the class where u define it, public allowes access from anywhereok
(i also assumed that ur
ItemShop
would implement the IPanel
here, could be different)
its after all just an example how to structure it ;pill give that a shot, thx fo the help
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.