C
C#3y ago
DayKnight

Programming with Paramerters (SOLVED) [Answered]

I have programmed for a few years now, and just figured that I can make cleaner code with Parameters. I try but I don't know what I am doing wrong
static void Main(string[] args)
{
numbers(4, 7);
}

public void numbers(int num1, int num2)
{
Console.WriteLine($"My fav number i {num1} but I also like the perfect number {num2} wow");
}
}
}
static void Main(string[] args)
{
numbers(4, 7);
}

public void numbers(int num1, int num2)
{
Console.WriteLine($"My fav number i {num1} but I also like the perfect number {num2} wow");
}
}
}
6 Replies
Angius
Angius3y ago
Well, numbers is a non-static method Main is static Non-static methods require an instance of an object Unless they're called in some other method of the same class One that isn't static, since static members have no direct access to non-static ones Either: a) Make your numbers static (and name it properly while at it) b) Instantiate the class and call numbers on that instance c) Create a non-static Main of sorts in a separate class
DayKnight
DayKnightOP3y ago
Oh! That's awesome, thanks for the explanation and the possible solutions ^^ It works perfectly now, I don't know why I din't use parameters before, it's amazing
Angius
Angius3y ago
Methods and parameters are one of the basics of the language, any programming language really. I'm amazed you managed without them lol
DayKnight
DayKnightOP3y ago
Yeah me too, no wonder why my code always was longer and more complicated than my colleagues Must be a pain to read and understand my code catlaugh
Angius
Angius3y ago
You can use /close command to close a thread
Accord
Accord3y ago
✅ This post has been marked as answered!
Want results from more Discord servers?
Add your server