Just declare the method as
public
:
public static void greet()
More info on accessibility levels:
Accessibility Levels - C# Reference | Microsoft Docs[
^]
Edit: re-reading your code carefully, when you define a method as
static
, you don't access it from an instance of the class, but from the class itself. So you have two choices:
Either you keep the method static, but modify your call accordingly:
using System;
namespace classes
{
public class Helper
{
public static void Greet()
{
Console.WriteLine("Hello");
}
}
class Caller
{
private static void Main(string[] args)
{
Helper.Greet();
}
}
}
This is the most sensible way, since a) you do not use any instance variable in the method. b) This simplifies the usage of the method (you don't have to create an instance of the Helper class).
Or you make the method an instance method:
using System;
namespace classes
{
public class Helper
{
public void Greet()
{
Console.WriteLine("Hello");
}
}
class Caller
{
private static void Main(string[] args)
{
var instance = new Helper();
instance.Greet();
}
}
}
Note that I also corrected the case of class and method, according to C# common accepted casing rules.