Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's Wrong With This? 2

Status
Not open for further replies.

RoguePoet01

Programmer
Oct 1, 2003
302
US
Hi,

I keep getting an error asking me to put a ";" at the end of the second line, after the "!= null)" part.

public void HirePerson(Person p) {
If ( m_OnNewHireDelegate != null )
m_OnNewHireDelegate(p);
}


But when I do that, then I get a different error telling me that the name "If" doesn't exist in the given class.

public void HirePerson(Person p) {
If ( m_OnNewHireDelegate != null )
m_OnNewHireDelegate(p);
}

Any ideas? Thanks.
 
That's so weird. I made the changes you suggested but it still wouldn't work, so I deleted the space between "...(Person p)" and "{" and then it worked.

Weird.

But thanks for your help.
 
Ohhhh!

I didn't notice the case-sensitive aspect of your reply.

Good to know. Thanks.
 
Poet, yeah, you had two basic problems. C# is case-sensitive. Also, the structure of the if statement requires that the condition be in parens, and that the code is enclosed in curlies.

As to extra spaces and so on, I've had this problem before with the forum, but only when dealing with Mac users in the PostScript programming forum. Our spaces aren't their spaces, and sometimes copy and pasting code is a problem. I don't know if that's the case here or not, just something to watch for.

Thomas D. Greer
 
Well actually, this works perfectly fine and I tend to use it a lot..

Code:
if(condition)
   onlyOneStatement;

// no braces!

But some people would call it bad practice. (What if someone editing the code doesn't notice the lack of braces and adds another statement?)

Anyway, the if statement does not require braces/curlies around the statement it executes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top