So I am in a programming discord server. I was bored so I wrote a random code snippet. Here's what I wrote:
using System;
class test {
public static double height = 1.82; // meters
public static void grow(double rate) {
height += rate;
}
}
class MainClass {
public static void Main(string[] args) {
test human = new test();
human.grow(0.05);
double height = human.height;
Console.WriteLine($"New height: {height}");
}
}
A user from the server said "[censored] incapaz thats awful" and I said "ofc it is", but in reality I didn't know what I did wrong. I only understand C# and a few other languages just from experience from past languages I learned.
He said it was awful because "the field and method are already static whats the point in new
ing an instance of test
".
So then I said, "what would u recommend", and he then said "if they're both static then it's really not even a class at that point it's like a namespace" and "if you want each test object to be independent, dont mark the fields and methods as static".
But i'm not exactly sure what he meant. Can somebody clear this up for me? I want to improve and learn.