C# FAQ: Why get an error (CS1006) when declaring a method without a return type?

Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio


Jump to: navigation, search
CSharp-Online.NET:FAQs
edit

Why get an error (CS1006) when declaring a method without a return type?

If you omit the return type of a method declaration, the compiler believes you are trying to declare a constructor. So, to declare a method that returns nothing, use void for the return type.

This example generates a CS1006 error:

public static aMethod (staticMain obj)   // CS1006 error 

This example is correct:

public static void aMethod (staticMain obj)


Personal tools