C#C
C#6mo ago
Faker

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

C#
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 method without creating an instance/object of the class UnitTest1 here please. When would we need to instantiate the class first then call the method?
Was this page helpful?