Is its possible to pass integer value as method arguments in C# console app

In my code

static void Main(string[] args)
{

}

what i want pass integer value in method args

static void Main(int? args)
{

}
Jon Skeet
people
quotationmark

You can't - you can only accept strings. However, you can then parse those strings as integers. For example:

static void Main(string[] args)
{
    int[] intArgs = args.Select(int.Parse).ToArray();
    // ...
}

Note that this will throw an exception if any of the arguments isn't actually an integer. If you want a more user-friendly message, you'll need to use int.TryParse instead, e.g.

static void Main(string[] args)
{
    int[] intArgs = new int[args.Length];
    for (int i = 0; i < args.Length; i++)
    {
        if (!int.TryParse(args[i], out intArgs[i]))
        {
            Console.WriteLine($"All parameters must be integers. Could not convert {args[i]}");
            return;
        }
    }
}

people

See more on this question at Stackoverflow