Overview of Unified Type System of C# (C Sharp)
Unified Type System means that C# follows a single type system to which all its data types belong. All the data types supported by C# fall under one roof called System.Object. Unlike Java and other programming languages, primitive types like int and byte are subclasses of System.Object .The term Unified Type System can also be called as Common Type System.
Great Savings... Everyday!
Tuesday, January 26th, 2021
CHECK NOW >>
Maintaining unified type system has many advantages. Few of them are mentioned below:
seamless integration between objects created in different language, thereby
Data types belonging to this Unified Type System can be classified into:
Types Variables defined using these data types directly hold the
Pointer Types are used only during a very specific case, when unsafe code is written. Value Types and Reference Types are the commonly used data types of C#. Given below is a compare and contrast chart on value types and reference types.
After reading these differences, no doubt that you wonder how both value types and reference types are part of unified type system using System.Object. But irrespective of these points, value types belong to System.Object. Each primitive type (like int, char) is an object. Consider the following piece of code:
Does this look strange?
This code is perfectly legal and the output will be 10. This is because the value type variable var1 is an object. Any object will have the following methods (with access modifier as public) by default:
This function is used to perform equality check. As already known, value
type equality check compares data and reference type equality check is
used to compare if both the references point to the same object. Return
type of this function is Boolean.
As per the
discussion till now, value types are objects. Now there arises a question.
Can value types be coded in a similar way as reference types? Yes, you
can. Heres an example:
In this example you assign var1 to an object and then you assign this object back to an int variable. This is perfectly legal and you have to cast the value explicitly when converting the object back to primitive type. This code internally uses boxing (converting int to object) and unboxing (converting object to in) concepts.
In general, objects have a considerable overhead in terms of performance and memory usage. In C#, value types can be used without any object behavior thereby eliminating its overhead. However if you still prefer to use the object oriented behavior of value type, you can go ahead with it as shown in the earlier example.
to our mailing list and receive new articles Note
: We never rent, trade, or sell my email lists to Visit
.NET Programming Tutorial Homepage ______________________________________________________
to our mailing list and receive new articles
: We never rent, trade, or sell my email lists to
Visit .NET Programming Tutorial Homepage
|Designing applications in .Net using Service Oriented Architecture | How to Create and Use Anonymous Delegates in C# (C Sharp) |How to Define Custom Attributes in C# (C Sharp)| How To Handle Errors While Developing ASP.NET Applications | How to Use Indexer in Classes and Interfaces of C# (C Sharp)| Illustration of Access Keywords (base, this) with Examples in C# (C Sharp) | Illustration of Null Coalesce Operator (??) in C# (C Sharp) |Indexers Vs Properties in C# (C Sharp) | More about Reserved Attributes of C# (C Sharp)| Overview of Unified Type System of C# (C Sharp) | Purpose of Delegates in C# (C Sharp) |How does Simple Object Access Protocol (SOAP) help in Internet Communication |How to Create and Use Anonymous Delegates in C# (C Sharp)|