In C#, why when we can define a class method and access to a method by class name directly, we should/some people define an object instead and then create an instance of that object?
Class1:
class Class1
{
public static int PrintX(int x)
{
return x;
}
private int y;
public int PrintY(int z)
{
return this.y = z;
}
}
Main Method:
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Class1.PrintX(9));
Class1 newClass = new Class1();
Console.WriteLine(newClass.PrintY(9));
}
}
Both ways print out 9. Why should I use an object method and then create an instance of it?!