C
C#•11mo 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•11mo ago
declare it the same way you did in that other class you shared preferably without all the unnecessary blank lines when
AlexTheMasterBG
AlexTheMasterBGOP•11mo ago
so like public static void printnumbers(int number) again in the program cs
Jimmacle
Jimmacle•11mo ago
try it
AlexTheMasterBG
AlexTheMasterBGOP•11mo ago
No description
Jimmacle
Jimmacle•11mo ago
declare it in the class, not inside Main just like you did in your Metodche class
AlexTheMasterBG
AlexTheMasterBGOP•11mo ago
oh wait so its basically declared in the class i dont get it
Jimmacle
Jimmacle•11mo 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
AlexTheMasterBGOP•11mo 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•11mo ago
sorry, that description is incredibly non-helpful
AlexTheMasterBG
AlexTheMasterBGOP•11mo ago
im sorry
Jimmacle
Jimmacle•11mo ago
i can only help if you can explain what you want
AlexTheMasterBG
AlexTheMasterBGOP•11mo ago
its hard since im learning it in another languidge i cant translate it too well
Jimmacle
Jimmacle•11mo ago
do you want to write a separate class to use in your program class's code?
AlexTheMasterBG
AlexTheMasterBGOP•11mo 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•11mo ago
correct, you are creating an instance of the class but you never actually call any methods on it
AlexTheMasterBG
AlexTheMasterBGOP•11mo ago
No description
Jimmacle
Jimmacle•11mo ago
also, your method is static which means you don't need an instance of the class anyway
AlexTheMasterBG
AlexTheMasterBGOP•11mo 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•11mo ago
Any particular reason you want the method to be in a different class?
AlexTheMasterBG
AlexTheMasterBGOP•11mo ago
not really my teacher in school wants me to do it that way
Pobiega
Pobiega•11mo ago
okay to call a static method, you need to specify class and method name like so: Class.Method();
AlexTheMasterBG
AlexTheMasterBGOP•11mo ago
like this ?
AlexTheMasterBG
AlexTheMasterBGOP•11mo ago
No description
Pobiega
Pobiega•11mo ago
yes - but your method takes an argument so you must pass that argument to it
AlexTheMasterBG
AlexTheMasterBGOP•11mo ago
No description
Pobiega
Pobiega•11mo ago
yup! you can now safely remove the line above it btw it does nothing
AlexTheMasterBG
AlexTheMasterBGOP•11mo ago
alright it works now Thanks !
MODiX
MODiX•11mo ago
Use the /close command to mark a forum thread as answered
AlexTheMasterBG
AlexTheMasterBGOP•11mo ago
can i add multiple arguments btw ? like if its for example public static void PrintNumbers(int numbers, string names, int age)
Pobiega
Pobiega•11mo ago
yes
Jimmacle
Jimmacle•11mo ago
give it a shot it's faster to try than to ask 😛
AlexTheMasterBG
AlexTheMasterBGOP•11mo ago
indeed
Want results from more Discord servers?
Add your server