-1

Possibly a stupid question but I need to ask it anyway for my own context. I have a non-static class that has a static method and a non-static method. What happens to the class, is it now a static class and a non-static class, meaning there is a static version of the class with just the static method in memory and when you instantiate the class there will be an instance with all the non-static methods? I may be confusing myself. C# .net framework. Non-static class with static and non-static method.

public class Class1
{
    public static string Class1Method()
    {
        return "static";
    }

    public void Class1Method2()
    {
        //Not Static
    }
}

Second class that would be using it.

public class Class2
{
    public void Class2Method()
    {
        Class1.Class1Method();
        new Class1().Class1Method2();
    }
}
NNassar
  • 485
  • 5
  • 11
  • 25

1 Answers1

1

Class1 is considered non-static.

However, if you were to run say ReSharper over Class1 as it appears above, it may suggest to you to consider making it static because Class1 has no instance members. i.e. static class Class1 as well as public static void Class1Method2.

Otherwise, as it stands now, there is no point to making Class1Method2 an instance method because there are no instance members to act upon.