Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Throw Exception from Expression in C# 7.0

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 331
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: