C
C#•10mo ago
AlexTheMasterBG

i am struggling to make a method code.

i am trying to declare my method in the program cs but i dont know how
No description
No description
32 Replies
Jimmacle
Jimmacle•10mo ago
declare it the same way you did in that other class you shared preferably without all the unnecessary blank lines when
AlexTheMasterBG
AlexTheMasterBG•10mo ago
so like public static void printnumbers(int number) again in the program cs
Jimmacle
Jimmacle•10mo ago
try it
AlexTheMasterBG
AlexTheMasterBG•10mo ago
No description
Jimmacle
Jimmacle•10mo ago
declare it in the class, not inside Main just like you did in your Metodche class
AlexTheMasterBG
AlexTheMasterBG•10mo ago
oh wait so its basically declared in the class i dont get it
Jimmacle
Jimmacle•10mo ago
i'm not sure you're using the correct terms here because what i'm telling you to do is to copy the method from your other class and paste it into your Program class where you want it is that not what you want?
AlexTheMasterBG
AlexTheMasterBG•10mo ago
well i want the code to work the thing i am trying to do is to do all the parameters and stuff in the class and then to make it so it lets me work with it
Jimmacle
Jimmacle•10mo ago
sorry, that description is incredibly non-helpful
AlexTheMasterBG
AlexTheMasterBG•10mo ago
im sorry
Jimmacle
Jimmacle•10mo ago
i can only help if you can explain what you want
AlexTheMasterBG
AlexTheMasterBG•10mo ago
its hard since im learning it in another languidge i cant translate it too well
Jimmacle
Jimmacle•10mo ago
do you want to write a separate class to use in your program class's code?
AlexTheMasterBG
AlexTheMasterBG•10mo ago
yeah basically ive made the method and i want to use it in the main because when i run the code like this it dosent execute the ifs from the method
Jimmacle
Jimmacle•10mo ago
correct, you are creating an instance of the class but you never actually call any methods on it
AlexTheMasterBG
AlexTheMasterBG•10mo ago
No description
Jimmacle
Jimmacle•10mo ago
also, your method is static which means you don't need an instance of the class anyway
AlexTheMasterBG
AlexTheMasterBG•10mo ago
so this Metodche PrintNumbers = new Metodche(); is unneeded ? yes and i dont know how to call the method into the program cs i do not know what the line of code for that is i just need to learn it and remember it so i can use the methods i put in classes to the program cs
Pobiega
Pobiega•10mo ago
Any particular reason you want the method to be in a different class?
AlexTheMasterBG
AlexTheMasterBG•10mo ago
not really my teacher in school wants me to do it that way
Pobiega
Pobiega•10mo ago
okay to call a static method, you need to specify class and method name like so: Class.Method();
AlexTheMasterBG
AlexTheMasterBG•10mo ago
like this ?
AlexTheMasterBG
AlexTheMasterBG•10mo ago
No description
Pobiega
Pobiega•10mo ago
yes - but your method takes an argument so you must pass that argument to it
AlexTheMasterBG
AlexTheMasterBG•10mo ago
No description
Pobiega
Pobiega•10mo ago
yup! you can now safely remove the line above it btw it does nothing
AlexTheMasterBG
AlexTheMasterBG•10mo ago
alright it works now Thanks !
MODiX
MODiX•10mo ago
Use the /close command to mark a forum thread as answered
AlexTheMasterBG
AlexTheMasterBG•10mo ago
can i add multiple arguments btw ? like if its for example public static void PrintNumbers(int numbers, string names, int age)
Pobiega
Pobiega•10mo ago
yes
Jimmacle
Jimmacle•10mo ago
give it a shot it's faster to try than to ask 😛
AlexTheMasterBG
AlexTheMasterBG•10mo ago
indeed
Want results from more Discord servers?
Add your server