If you like this article, please click on “+1“ button and share with your friends.
Click here for the Video Tutorial of this article.
visit www.iGnani.com
…continued from previous article “C# 4.0 – Ch:01:A – Introduction” |
In this chapter, I am going to get close-up with .NET. Let us look at some of the features that it provides us.
Object Orientation
.NET supports object-oriented programming, with single implementation inheritance of classes and includes encapsulation, inheritance, and polymorphism.
I am not going to get into more detail with this topic, since it has a complete chapter dedicated for this purpose. We shall look at OOPs while working with C#.
Strong Data Typing
Arguably Strong Data typing is one of the best features of .NET. Unlike languages like Visual Basic 6 or Scripting languages which uses Variant data type, .NET specifies that all variables are clearly marked as being of a particular data type. It does not support the code that result in ambiguous data types. Though some languages compatible with .NET, such as Visual Basic 2010, still allow some loosely typed data types, when that code is compiled, the compilers behind the scenes ensure that the type safety is enforced in the resulting Intermediate Language code. Also Managed C++ allows pointers to be used, but then the resulting code cannot get the benefits like Garbage collection, etc.
Strong Typing vs. Loose Typing
A type system is said to feature strong typing when it specifies one or more restrictions on how operations involving values of different data types can be intermixed. .NET which supports strong typing prevents the successful execution of an operation on arguments that have the different types.
The opposite of strong typing is loose or weak typing. Weak typing means that a language implicitly converts or casts data types when used.
Consider an example using the Weak typing using the Variant data type.
var x = 5; // x is an integer
var y = "10"; // y is a string
x + y; // Answer differs between Strong Typed Language and Weak Typed Language
Type Safety in C#
C# is primarily a strongly typed or type-safe language, where in data types can interact only through protocols they define, thereby ensuring type safety. For example, in C# you cannot interact with a string type as an
integer type without type casting the same.
In addition to dynamic type safety enforced by .NET CLR at runtime, C# also supports static typing, where in the language enforces type safety at compile time. Static typing eliminates a large class of errors before a program is even run and there by taking away the burden from unit testing onto the compiler by verifying that all the types in a program fit together correctly. Static typing makes large programs a lot easier to manage, more predictable and more robust. In Visual Studio, it allows tools such as IntelliSense to help you write a program easily, since it knows before hand a given variable’s type and hence the methods are provided and properties it provides.
Although, C# 4.0 allows parts of your code to be dynamically typed via the new dynamic keyword, still C# remains a predominately statically typed language.
next article “C# 4.0 – Ch:01:C – Language Interoperability”…. |
visit www.iGnani.com
MicroMind Information Systems
#4013, K.R. Road, Banashankari II Stage,
BANGALORE - 560070
KARNATAKA, INDIA
Phone: +91 80 26762747
No comments:
Post a Comment