5 Replies - 975 Views - Last Post: 04 January 2008 - 01:16 PM Rate Topic: -----

#1 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Problems with Constructors {Resolved = true;}

Post icon  Posted 13 December 2007 - 12:58 AM

I'm creating a C# class file for some freelance work I am doing. I was writing a constructor, which most class files need:

public InviteSender()
{

}



But InviteSender is underlined with the error

Quote

Class, struct, or interface method must have a return type


Now I know they have me on a ton of pain pills and such, but a constructor is a constructor and the one I posted above appears just find to me, can anyone find any mistakes in it?

Is This A Good Question/Topic? 0
  • +

Replies To: Problems with Constructors {Resolved = true;}

#2 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5795
  • View blog
  • Posts: 12,628
  • Joined: 16-October 07

Re: Problems with Constructors {Resolved = true;}

Posted 13 December 2007 - 04:54 AM

The only reason I can think of that you would get this is if it didn't see it inside the class, e.g
class InviteSender {
} // oops
public InviteSender() { }


Was This Post Helpful? 0
  • +
  • -

#3 antonio71  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-December 07

Re: Problems with Constructors {Resolved = true;}

Posted 15 December 2007 - 08:01 PM

That's right. We all know that constructors must be WITHIN the class of the same name.
Was This Post Helpful? 0
  • +
  • -

#4 orcasquall  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 12
  • View blog
  • Posts: 158
  • Joined: 14-September 07

Re: Problems with Constructors {Resolved = true;}

Posted 17 December 2007 - 06:29 AM

I might have found the cause. This will give the same error:
class Class2
{
	public Class1()
	{
	}
}


The squiggly error underline is under "Class1".

My guess is the constructor is named after the wrong class.
Was This Post Helpful? 0
  • +
  • -

#5 abbie  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-January 08

Re: Problems with Constructors {Resolved = true;}

Posted 04 January 2008 - 12:17 PM

Does anyone know how to do methods in c# ? tnx :)
Was This Post Helpful? 0
  • +
  • -

#6 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Problems with Constructors {Resolved = true;}

Posted 04 January 2008 - 01:16 PM

http://www.c-sharpco...MethodsP_1.aspx

http://www.codersour...properties.html

http://www.youcanlea...ingMethods.aspx

http://www.aspfree.c...Methods-part-1/
http://www.google.ca...lient=firefox-a
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1