
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are Object Data Types in C#
The object types can be assigned values of any other types, value types, reference types, predefined or user-defined types. However, before assigning values, it needs type conversion.
The Object Type is the ultimate base class for all data types in C# Common Type System (CTS). Object is an alias for System.Object class.
When a value type is converted to object type, it is called boxing and on the other hand, when an object type is converted to a value type, it is called unboxing.
The following is an example −
object obj; obj = 100; // this is boxing
Here is the complete example showing the usage of object data types −
Example
using System; using System.IO; namespace Demo { class objectClass { public int x = 200; } class MyApplication { static void Main() { object obj; obj = 50; Console.WriteLine(obj); Console.WriteLine(obj.GetType()); Console.WriteLine(obj.ToString()); obj = new objectClass(); objectClass newRef; newRef = (objectClass)obj; Console.WriteLine(newRef.x); } } }
Output
50 System.Int32 50 200
Advertisements