Difference between IS and AS keyword in C#


IS keyword is responsible for checks whether  an object is compatible with a given type and the result of the evaluation is a Boolean (true, false).
For example:
        public void emp()
        {
            Employee oEmp = new Employee();
            if (oEmp is Employee)
            {
            // your code
            }
        }

AS keyword is responsible for the casting of the object to a given type or class.
for Example :

Employee o = oEmp as Employee;

No comments:

Post a Comment

Please do not enter any spam link in the comment box.

Related Posts

What is the Use of isNaN Function in JavaScript? A Comprehensive Explanation for Effective Input Validation

In the world of JavaScript, input validation is a critical aspect of ensuring that user-provided data is processed correctly. One indispensa...