object obj = "hello world"; string str = obj as string; if (str != null) { Console.WriteLine(str.ToUpper()); }
object obj = 12345; int num = obj as int; // invalid codeIn this example, we have an object that is an integer. We try to cast it as an int type using the `as` keyword, but this will result in a compile-time error. This is because `int` is a value type and cannot be null, so we cannot use the `as` keyword with it. Instead, we must use the `is` keyword to check if the object is of a certain type or cast it using the regular casting syntax. Package Library: The EntityType As feature is a built-in feature of C# and does not require any additional package or library.