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