john
john

Reputation: 73

Parameter args of method main never used

I've installed Microsoft.CodeAnalysis.FxCopAnalyzers, Roslynator.Analyzers, SonarAnalyzer.CSharp, StyleCop.Analyzers to help me write better code in C#, but I get an error whenever I write code, even if it`s 1 line. The error says:

"Parameter args of method main never used"

How can I fix it and why do I get the error?

enter image description here

using System;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {

            int n = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(n);


        }
    }
}

Upvotes: 1

Views: 1897

Answers (3)

Salah Akbari
Salah Akbari

Reputation: 39956

Actually since you didn't use the args parameter in your method, you can safely remove it. But FYI, you can pass some args to this method that could be sometimes helpful, by right clicking on the project you are working on and choosing the properties, then by going to the Debug tab and then, on the Start Options section provide the app with your args, just like the following image:

enter image description here

Upvotes: 0

NoviceProgrammer
NoviceProgrammer

Reputation: 3365

The parameters are optional in the main method and can be removed if you don't need to use command line arguments.

This code is also valid:

internal static Program
{
    private static void Main()
    {
        // 
    }
}

Upvotes: 4

Nulltiton
Nulltiton

Reputation: 25

You don't use the args parameter in Main. Remove it if you will not use it further.

Code:

static void Main()
{
    int n = Convert.ToInt32(Console.ReadLine());
    Console.WriteLine(n);
}

Upvotes: 0

Related Questions