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