as
|
is
|
Is Operator is used to check the Compatibility of an Object with a given Type and it returns the result as a Boolean (True or false).
|
As Operator is used for Casting of Object to a given Type or a Class.
|
Ex:
if (someObject is StringBuilder) ...
|
Ex:
object x = 5;
// int y = x as int; // not allowed becoz of int : value type
int? y = x as int?; // allowed becoz of nullable type
Ex.
Student s = obj as Student;
is equivalent to:
Student s = obj is Student ? (Student)obj : (Student)null;
|
as operator should be used with Reference Type or nullable type
|
Solution for the QlikView, Biztalk, DotNet and MSBI real time development problems
Search This Blog
Friday, March 4, 2016
Difference between as and is in C#
Labels:
.Net Interview Questions,
C#,
C# FAQS
Subscribe to:
Post Comments (Atom)
Popular Posts
-
Error : Could not store transport type data for Receive Location 'EAISolutionReceiveRequestLocation' to config store. Prima...
-
I am getting below error while executing stored procedure from C# (Ado.net, entity framework) String[2]: the Size property has an invalid ...
-
Migration from Visual Studio 2008 to 2013 Without any code changes I successfully migrated from VS 2008 to 2013 but when running website f...
-
Exception : Microsoft.WindowsAzure.StorageClient.StorageClientException was unhandled Message=One of the request inputs is out of ran...
-
Review the permissions of the user that you're trying to impersonate. In my situation, I was only getting the error on my development ...
No comments:
Post a Comment