Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 10th Oct 2012, 03:57 PM   #1
Hyper internet marketer
War Room Member
 
Join Date: 2010
Location: Europe and Pakistan
Posts: 478
Thanks: 184
Thanked 21 Times in 18 Posts
Lightbulb
Error coming c# Please look
Share on: 
fb share twitter share gplus share more share

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();
}
}

}

extremeboy is offline  
Unread 10th Oct 2012, 04:06 PM   #2
White Hat Marketer
War Room Member
 
Dan Grossman's Avatar
 
Join Date: 2007
Location: Montgomeryville, PA
Posts: 1,546
Thanks: 77
Thanked 775 Times in 267 Posts
Default
Re: Error coming c# Please look
Share on: 
fb share twitter share gplus share more share

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.

Improvely: Built to track, test and optimize your marketing.

[SIGPIC][/SIGPIC]
Dan Grossman is offline  
The Following User Says Thank You to Dan Grossman For This Useful Post:
Unread 10th Oct 2012, 05:18 PM   #3
Hyper internet marketer
War Room Member
 
Join Date: 2010
Location: Europe and Pakistan
Posts: 478
Thanks: 184
Thanked 21 Times in 18 Posts
Default
Re: Error coming c# Please look
Share on: 
fb share twitter share gplus share more share

Originally Posted by Dan Grossman View Post

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.
Reallly thank it worked

extremeboy is offline  
Closed Thread


Bookmarks

Tags
coming, error


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 02:02 AM.