© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•8mo ago•
25 replies
Faker

✅ When can we call a non-static method without creating an object?

namespace GitHubAction.Test;

public class UnitTest1
{
    [Fact]
    public void PassingTest()
    {
        Assert.Equal(4, Add(2, 2));
    }

    [Fact]
    public void FailingTest()
    {
        Assert.Equal(5, Add(2, 2));
    }

    int Add(int x, int y)
    {
        return x + y;
    }
}
namespace GitHubAction.Test;

public class UnitTest1
{
    [Fact]
    public void PassingTest()
    {
        Assert.Equal(4, Add(2, 2));
    }

    [Fact]
    public void FailingTest()
    {
        Assert.Equal(5, Add(2, 2));
    }

    int Add(int x, int y)
    {
        return x + y;
    }
}

Hello, can someone explain why can we call the
Add
Add
method without creating an instance/object of the class
UnitTest1
UnitTest1
here please. When would we need to instantiate the class first then call the method?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Can i not call a non static Method in a interface?
C#CC# / help
3y ago
object reference not set to instance of object on a static method call
C#CC# / help
3y ago
Cannot access non-static method in static context?
C#CC# / help
4y ago