Error coming c# Please look

2 replies
Hello

I am new to C# so i was just doing practice with tutorials i get this error:

"method must have return type"

for those two places:
public emp()
public emp(string varname,int varage)


Help will be apprecited thanks!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
class Program
{


private string name;
private int age;

public emp()
{
name ="Mark";
age=23;

}

public emp(string varname,int varage)

{
name=varname;
age=varage;

}

public void displayit()

{
Console.WriteLine("Name ="+name);
Console.WriteLine("Age="+age);
}
static void Main(string[] args)
{
emp obempone=new emp();
emp obemptwo=new emp("Allen",30);
obempone.displayit();
Console.WriteLine();
obemptwo.displayit();
}
}

}
#coming #error
  • Profile picture of the author Dan Grossman
    You're trying to create a constructor named "emp", but your class is not named "emp", it's named "Program". A class and its constructor method have the same name.

    Since this method does not match any class name, the compiler expects you're creating a normal method, not a constructor, and methods have return types.
    Signature
    Improvely: Built to track, test and optimize your marketing.

    {{ DiscussionBoard.errors[7144593].message }}

Trending Topics