Throw Exception from Expression
When we use throw exception inside expression we got compile time error
In C# 7.0 you can directly throw exception from your expression directly. see below code
public string getEmpInfo( string EmpName)
{
string[] empArr = EmpName.Split(",");
return (empArr.Length > 0) ? empArr[0] : throw new Exception("Emp Info Not exist");
}
In above code we can directly throw exception from return statement.
0 Comment(s)