Thursday, 19 September 2013

New features in C# 4.0

The major theme for C# 4.0 is dynamic programming. Increasingly, objects are “dynamic” in the sense that their structure and behavior is not captured by a static type, or at least not one that the compiler knows about when compiling your program. Some examples include

Objects from dynamic programming languages, such as Python or Ruby
COM objects accessed through IDispatch
Ordinary .NET types accessed through reflection
Objects with changing structure, such as HTML DOM script objects
Data readers and other user defined dynamic objects

While C# remains a statically typed language, we aim to vastly improve the interaction with such objects.
A secondary theme is co-evolution with Visual Basic. Going forward we will aim to maintain the individual character of each language, but at the same time important new features should be introduced in both languages at the same time. They should be differentiated more by style and feel than by feature set.

The new features in C# 4.0 fall into four groups:
Dynamic binding
Dynamic binding allows you to write method, operator and indexer calls, property and field accesses, and even object invocations which bypass the C# static type checking and instead gets resolved at runtime. 

Named and optional arguments
Parameters in C# can now be specified as optional by providing a default value for them in a member declaration. When the member is invoked, optional arguments can be omitted. Furthermore, any argument can be passed by parameter name instead of position.

COM specific interop features
Dynamic binding as well as named and optional arguments help making programming against COM less painful than today. On top of that, however, we are adding a number of other features that further improve the interop experience specifically with COM.

It used to be that an IEnumerable<string> wasn’t an IEnumerable<object>. Now it is – C# embraces type safe “co-and contravariance,” and common BCL types are updated to take advantage of that.

I will come with more details on this in next blog....

Tuesday, 10 September 2013

Microsoft's .NET Framework

Microsoft's .NET Framework is comprised of two main components - the Common Language Runtime (CLR) and the .NET Framework class libraries. The CLR is the real foundation of the .NET Framework. It is the execution engine (runtime environment) for all .NET applications. Every target computer requires the CLR to successfully run a .NET application that uses the .NET Framework. The main features of CLR include:
1.    Automatic Memory Management.
2.    Thread Management.
3.    Code Compilation & Execution.
4.    Code Verification.
5.    High level of security.
6.    Remoting.
7.    Structured Exception Handling.
8.    Interoperability between Managed and Unmanaged code.
9.    Integration with Microsoft Office System

All .NET applications are compiled into
Intermediate Language code (MSIL). When executed on the CLR, MSIL is converted into native machine code specific to the operating platform. This process is done by a Just In Time (JIT) compiler. The code executed by the CLR is called as Managed Code. This code is type safe and thoroughly checked by the CLR before being deployed.

The .NET runtime also provides a facility to incorporate existing COM components and DLL's into a .NET application. Code that is not controlled by the CLR is called Unmanaged Code.

One of the interesting points to note is that the CLR itself manages the life of objects. This is the effect of the Automatic Garbage Collection system built into it. When the CLR finds an object that is not being used, it destroys them and thus frees their memory allocation.

The .NET Framework is further comprised of
Common Type System (CTS) and Common Language Specification (CLS). The CTS defines the common data types used by .NET programming languages. The CTS tells you how to represent characters and numbers in a program.
The CLS represents the guidelines defined by for the .NET Framework. These specifications are normally used by the compiler developers and are available for all languages, which target the .NET Framework.

Explain CLS and CTS?
CLS: Common Language specification is a set of rules that are to be followed by a language in order to be .NET complaint. This facilitates cross-language integration. Programs written in one .NET language can interoperate with programs written in another .NET language.

Common language specification defines the common types that are supported by the languages which are compatible with the .net framework. For example if u develop a web service with functions which are accepting unsigned integer values as parameter and u want to use that service in a language that won't supports unsigned integers then u will get a problem .So the languages which wants to be compatible with .net must support the types that are specified by CLS.

CTS: Common Type System
Common Type System (CTS) describes how types are declared, used and managed. CTS facilitate cross-language integration, type safety, and high performance code execution.

CTS are the service which is used by the CLR to manage the code. CTS can express the semantics of any programming language. CTS define a standard set of types and rules to create new types. The runtime understands how to create and execute these types. Compilers and interpreters use the runtime (CLR) services like CTS to define types, manage objects and make method calls instead of using tool or language specific methods. CTS goal is to enable multi language integration.

Monday, 9 September 2013

Saturday, 7 September 2013

Sample of Various Design Patterns

Sample of Various Design Patterns

1. AbstractFactory
2. Factory
3. BuilderPattern
4. Singleton

C# & Encapsulation

Encapsulation means to create a boundary around an object to separate its external (public) behavior from its internal (private) implementation.

Consumers of an object should only concern themselves with what an object does, not how it does it. 

C# supports encapsulation via:

– Unified Type System
– Classes and Interfaces
– Properties, Methods and Events

C# & Inheritance

C# implements Inheritance in two ways:

– A class may inherit from a single base class
– A class may implement zero or more Interfaces.

C# & Polymorphism

– A class can be used as its own type, cast to any base types or interface types it implements.
– Objects may methods as virtual; virtual methods may be overridden in a derived type. These are executed instead of the base implementation                         

What is Object Oriented Programming?

To be object oriented, a language is designed around the concept of objects. that are something, have certain properties and exhibit certain behaviors. This means the language generally includes support for:

– Encapsulation
– Inheritance
– Polymorphism                         

What is an Object?

An object typically models a concept:

– An object usually “is” something –i.e. a customer
– An object usually “has” data –i.e. the customer’s first name
– An object usually “performs” actions –i.e. make a customer “preferred”