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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exit / end function

Status
Not open for further replies.

cathiec

Programmer
Oct 21, 2003
139
IE
is there a way in c# to exit out of a function like in vb (exit function)
i am using a variable and an if statement. if this variable is null i want to exit out of the function without continuing with the rest of the vode in the function.



try
{
SearchResult result = search.FindOne();
//i want to exit the procedure here if result is 0
if(result == null)
{
???????????
}

int propertyCount = result.Properties["memberOf"].Count;
String dn;
int equalsIndex, commaIndex;

for( int propertyCounter = 0; propertyCounter < propertyCount;
propertyCounter++)
{
dn = (String)result.Properties["memberOf"][propertyCounter];

equalsIndex = dn.IndexOf("=", 1);
commaIndex = dn.IndexOf(",", 1);
if (-1 == equalsIndex)
{
return null;
}
groupNames.Append(dn.Substring((equalsIndex + 1),
(commaIndex - equalsIndex) - 1));
groupNames.Append("|");
}

}
catch(Exception ex)
{
throw new Exception("Error obtaining group names. " +
ex.Message);
}
 
Use return keyword
Code:
void MyFunction(int i)
{
 if(i==1)
 {
  //code here
  //exit the function
  return;
 }
}

bool MyFunction(int i)
{
 if(i==1)
 {
  //code here
  //exit the function
  return true;
 }
 return false;
}

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top