DOT NET 4.0 – The significance of .NET and C#

. NET is a new framework – a new API – for programming on the windows platform. Along with .NET framework, C# is a new language that has been designed from scratch to work with .NET as well as to take advantage of all the progress in developer environments and in our understanding of object oriented programming principles that have taken place over the past 20 years.

The basic difference between the .NET release and the earlier version of windows based products is that backward compatibility has not been lost in the process. Existing programs will continue to work, and .net was designed with the ability to work with existing software. Communication between software components on windows presently almost entirely takes place using COM. Taking account of this, .NET does have the ability to provide wrappers around existing COM components so that .NET components can talk to them.

It is true that you don’t need to learn c# in order to write code for .NET. Microsoft has extended c++ provided another new language called j#, and made substantial changes to visual basic to turn it into more power language VB.NET, in order to allow code written in either of these languages to target the .NET environment.  These other languages, however are hampered by the legacy of having evolved over the years rather than having been written from the start with today’s technology in mind.

Advantages of .NET

Object Oriented Programming – both the .NET framework and C# are entirely based on object-oriented principles right from the start.

Good Design – a base class library, which is designed from the ground up in a highly intuitive way.

Language Independence – with .NET all of the language VB.NET, c#, J#, and managed C++ compile to common Intermediate Langue. This means that languages are inter operable in a way that has not been seen before

Better support for Dynamic Web pages – While ASP offered a lot of flexibility, it was also inefficient because of its use of interpreted scripting languages, and the lack of object-oriented design often resulted in messy ASP code. .NET offers an integrated support for web pages, using a new technology- ASP.NET with ASP.NET code in your pages is compiled, and may be written in a .NET aware high level languages such as c#, j#, VB.NET.

Efficient data access – a set of .NET components, collectively known as ADO.NET, provides efficient access to relational databases and a variety of data sources. Components are also available to allow access to the file system, and to directories. In particular, XML support is built into .NET, allowing you to manipulate data, which may be imported from or exported to non windows platforms.

Code sharing – .NET has completely revamped the way that code is shared between applications, introducing the concept of assembly, which replaces the traditional DLL. Assemblies have formal facilities for versioning, and different versions of assemblies can exist side by side.

Improved Security – each assembly can also contain built in security information that can indicate precisely who or what category of user or process is allowed to call which methods on which classes. This gives you a very fine degree of control over how the assemblies that you deploy can be used.

Zero Impact Installation – there are two type of assembly: shared and private. Shared assemblies are common libraries available to all software, while private assemblies are intended only for use with particular software. A private assembly is entirely self-contained, so the process of installing it is simple. There are no registry entries; the appropriate files are simply placed in the appropriate folder in the file system.

Support for web services – .NET has fully integrated support for developing web services as easily as you would develop any other type of application.

Visual studio .NET 2003 – .NET comes with a developer environment. VS.NET which can cope equally well with c++, C#, J#, VB.NET as well as ASP.NET code. It integrates all the best features of respective language-specific environments of VS6.

C# – C# is a new object oriented language intended for use with .NET

The first version of .NET framework 1.0 was released in 2002 to much enthusiasm. The latest version of .NET framework 1.1 was introduced in 2003 and is considered a minor release of the framework, but definitely deserves some attention.

***************************************************************************************

Some of breaking changes that are new to .NET framework 1.1 as well as VS.NET 2003 are

Mobility –  When using .NET framework 1.0 and VS.NET 2002, to be able to build mobile applications you had to go out and download Microsoft Mobile Internet Toolkit (MMIT). Now, with 1.1 and VS.NET 2003, this is built right in and therefore no separate download is required.

This is quite evident when you create a new project using VS.NET 2003. When you look at list of available C# project types you can create, you will find ASP.NET mobile web application and smart device application. You would use ASP.NET mobile web application project type to build web based mobile application. Building smart device application allows you to create applications for the pocket PC or any other windows CE device. The thick client application built for windows CE device utilize the compact framework, a trimmed down version of the .NET framework.

New Data Providers –

ADO.NET is the way of accessing and working with data, now has two new data providers – one for ODBC and another for oracle.

With the .NET framework 1.1, the ODBC data provider is built right in, and no separate download is required.  Sytem.Data.Odbc namespace gives you access to ODBC data connection, data provider, data adapter, and data reader objects.

The other new data provider is for working with oracle databases. This database is quite popular in the enterprise space, and the lack of oracle data provider often times was a big barrier for .NET to enter this space. To work with this new data provider, you will need to make a reference to the System.Data.OracleClient namespace in your project.

A new Language: Visual J#

J Sharp is very similar to the java language. The hope with this language is that java developers will find it an easy transition to .NET. A J# developer will use the .NET class libraries in place of the java runtime libraries.

Side by Side Execution:

Side-by-side execution is the ability to run multiple versions of application on the same server where different application versions target different runtime versions. With the release of second version of framework(1.1), we can build new versions of your .net applications that target this latest .net framework, but at the same time you can allow the older versions of your application that target the .NET framework 1.0 to continue to work just as they always have.

Support for Internet Protocol Version (IPV6)

Ipv6 is support3ed in .NET 1.1 through System.Net namespace as well as in ASP.NET and XML web services.

VS.NET 2003 enhancements

You can upgrade the projects built using VS.NET 2002, to VS.NET 2003 with a better IDE with smarter Intellisense and code completion.

************************************************************************************************

Where C# Fits in;

C# can be seen as being the same thing to programming languages as .NET is to the Windows environment. Microsoft has been adding more and more features to Windows API, Visual basic and C++. Although VB and c++ have ended up as hugely powerful languages as a result of this, both languages also suffer from problems due the legacies of how they have evolved.

In case of VB6 and earlier, the main strength of the language was the fact that it was simple to understand and did make many programming tasks easy, largely hiding the details of the windows API and the COM component infrastructure from the developer. The downside to this was the Visual basic was never truly object oriented, so that large applications quickly become disorganized and hard to maintain. It didn’t really lend itself to well-structured or object-oriented programs.

C++, on the other hand, has its roots in the ANSI C++ language definition, Though Microsoft first wrote its C++ compiler before the ANSI definition has become official, but it comes close. Microsoft has been simultaneously trying to evolve c++ into a language that is designed for high performance tasks on windows, and in order to achieve that they have been forced to add a huge number of Microsoft specific keywords as well as various libraries to the language. The result is that on windows , the language has become a complete mess. Just ask C++ developers how many definitions for a string they can think of char*, LPTSTR, string, Cstring(MFC version), Cstring(WTL version, wchar_t*, OLECHAR* and so on.

Now enter .NET – completely new environment that is going to involve new extensions to both languages. Microsoft has done the ground work and completely revamped into Visual Basic.NET by retaining the some of the basic VB sytax and keywords.

It’s in this context that Microsoft has decided to give developers an alternative language designed specifically .NET and designed with a clean slate. Visual C#.NET is the result. Microsoft describes C# as a “simple modern, object-oriented, and type-safe programming language derived from c and c++. Most independent observers would probably change that to “derived from c, c++ and java.” Sytactically, c# is very similar to both C++ and java, to such an extent that many keywords are the same, and c# also shares the same block structure with braces ({ }), however c# code is easier to learn that C++ and java.

It has been designed to give us, simultaneously, the ease of use of visual basic, and the high performance, low-level memory access of C++ if required.

***********************************************************************************************

Some of C# features are:

–          Full support for classes and object-oriented programming, including both interface and implementation inheritance, virtual functions, and operator overloading.

–          A consistent and well defined set of basic types.

–          Built-in support for automatic generation of XML documentation

–          Automatic cleanup of dynamically allocated memory

–          Full access to .NET base class library, as well as easy access to windows API(if you really need it, which won’t be all that often)

–          Pointers and direct memory access are available if required, but the language has been designed in such a way that you can work without them in almost all cases.

–          Support for properties and events in the style of Visual basic

–          Just by changing the compiler options, you can compile either to an executable or to a library of .NET components that can be called up by other code in the same way as ActiveX controls (COM Components)

–          C# can be used to write ASP.NET dynamic web pages and XML web services

Couple of C# limitations:

The one area that language is not designed for is time-critical or extremely high performance code – the kind where you really are worried about whether a loop takes 1000 or 1050 machine cycles to run through, and you need to clean up your resources the millisecond they are no longer needed. C++ is likely to continue to reign supreme among low-level languages in this area. C# lacks certain key facilities need for extremely high performance apps, including the ability to specify inline functions and destructors that are guaranteed to run at particular points in the code. However, the proportions of applications that fall into this category are very low.

**********************************************************************************************

WHAT YOU NEED TO WRITE AND RUN C# CODE.

.NET will run on windows 98, 2000, XP and 2003. The full .NET SDK isn’t needed to run managed code, but .NET runtime is needed. You may need to distribute the .NET runtime with your code for the benefit of those clients who do not have it already installed.

***********************************************************************************************

Relationship of C# to .NET

–          It is specifically designed and targeted for use with Microsoft’s .NET framework ( a feature-rich platform for the development, deployment, and execution of distributed applications).

–          It is a language based on the modern object-oriented design methodology, and when designing it Microsoft has been able to learn from the experience of all other similar languages that have been around since Object-oriented principles came to prominence some 20 years ago.

–          C# is designed to generate code that targets the .NET environment

**************************************************************************************************

Common Language Runtime:

Central to the .NET framework is its runtime execution, known as CLR or .NET runtime. Code running under the control of the CLR is often termed managed code.

However, before it can be executed by CLR, any source code that we develop needs to be compiled. Compilation occurs in two steps

  1. Compilation of source code to IL
  2. Compilation of IL to platform-specific code(native code) by the CLR

This two stage compilation process is very important, because the existence of IL is the key to providing many of the benefits to .NET.

Advantages of Managed Code

Microsoft intermediate language shares with java byte code the idea that it is a low level language with a simple syntax(based on numeric codes rather than text), which can be very quickly translated into native machine code. Having this well defined universal syntax for code has significant advantages.

Platform Independence

First, it means that the same file containing byte code instructions can be placed on any platform, at runtime the final stage of compilation can be easily accomplished so that the code will run on that particular platform. In other words, by compiling to IL we obtain platform independence for .NET, in much the same way as compiling to java byte code gives java platform independence.

Performance improvement

Although we previously made comparisons with java, IL is actually a bit more ambitious than java byte code. IL is always Just in Time compiled(JIT) where as java byte code was often interpreted. One of the disadvantages of java was that, on execution, the process of translating from java byte code to native executable resulted in a loss of performance ( with the except ion of more recent cases, where java is JIT compiled on certain platform).

Instead of compiling the entire application in one go (which could lead to a slow start-up time), the JIT compiler simply compiles each portion of code as it is called (JIT). When code has been compiled once, the resultant native executable is stored until the application exits, so that it does not need to be recompile4d the next time that portion of code is run. Microsoft argues that this process is more efficient than compiling the entire application code at the start, because of the likelihood that large portions of any application code will not actually be executed in any given run. Using the JIT compiler, such code will never be compiled.

This explains why we can expect that execution of managed will be as fast as executing native machine code. Microsoft expects that we will get a performance improvement. The reason given for this is that, since the final stage of compilation takes place at runtime, the JTI compiler will know exactly what processor type the program will run on. This means that it can optimize the final executable code to take advantage of any features or particular machine code instructions offered by that particular processor.

Language Interoperability

The use of IL not only enables platform independence, it also facilitates language interoperability. Simply put, you can compile to IL from one language, and this compiled code should then be interoperable with code that has been compiled to IL from another language.

COM and COM+

Technically speaking, COM and COM+ aren’t technologies targeted at .NET, because components based on them cannot be compiled into IL. However, COM+ remains an important tool, because its features are not duplicated in .NET.  Also, COM components will still work and .NET incorporates com interoperability features that make it possible for managed code to call up COM components and vice versa.

Intermediate Language (IL)

We understand that our C# code will be compiled into IL before it is executed (indeed, the c# compiler only compiles to managed code).

The important feature of IL:

Object-Orientation and use of interfaces:

The language independence of .NET does have some practical limitations. IL is inevitably going to implement some particular programming methodology, which means the languages targeting it are going to have to be compatible with that methodology. The particular route that Microsoft has chosen to follow for IL is that of classic object-oriented programming, with single implementation of inheritance of class

Besides that, IL also brings in the idea of interfaces, which saw their first implementation windows with COM.

Language Interoperability

After all, C++ and java both use the same object oriented paradigms, but they are still not regarded as interoperable. COM allowed components written in different language to work together in the sense of calling each other’s methods. What was inadequate about that? COM by virtue of being standard, did allow components to instantiate other components and call methods or properties against them, without worrying about the language the respective components were written in. However, each object had to be instantiated through COM runtime and accessed through interface. The emphasis was very much that components could talk to each other, but only via COM runtime. In no way with COM did components written in different languages directly communicate with each other, or instantiate each other- it is always done with COM as an intermediary.  Not only that, but COM doesn’t support implementation inheritance. In addition to the above-mentioned problem, you would still have to debug components written in different languages independently. It was not possible to step between languages in the debugger.

So we really mean by language interoperability is that classes written in one language should be able to talk directly to classes written in another language. In particular

– A class written in on language can inherit from a class written in another language

– The class can contain an instance of another class, no matter what the languages of the two classes are

– An object can directly call methods against another object written in another language

– Objects(or reference to objects) can be passed around between methods

– When calling methods between languages we can step between the method calls in the debugger, even when this means stepping between source code written in different languages.

Strong distinction between value and reference types

IL provides a number of predefined primitive data types. One characteristic of IL, however, is that it makes a strong distinction between value and reference types. Value types are those for which a variable directly stores its data, while reference types are those for which a variable simply stores the address at which the corresponding data can be found.

IL also lays down specifications about data storage: instances of reference types are always stored in an area of memory known as managed heap, while the value types are normally stored in stack

Strong data typing

IL is based on exceptionally strong data typing. What we mean by that is that all variables are clearly marked as being of particular, specific data type ( there is no room in IL for eg variant in visual basic and scripting languages).

Importance of strong data typing for language interoperability

If a class is to derive from or contains instances of other classes, it needs to know about all the data types used by the other classes. This is why strong data typing is so important. Indeed, in the absence of any agreed system for specifying this information in the past has always been the real barrier to inheritance and interoperability across languages.

Common Type system

CTS defines the predefined data types that are available in IL, so that all languages that target the .NET framework will produce compiled code that is ultimately based on these types.

For example VB.NET’s Integer is actually a 32 bit signed integer, which maps exactly to the IL type known as Int32. This will there be the data type specified in the IL code. Because C# compiler is aware of this type, there is no problem. At source code level c# refers to Int32 with the keyword int, so the compiler will simply treat the visual basic.net method as if it returned an int.

CTS doesn’t merely specify primitive data types, but a rich hierarchy of types, which includes well defined points in the hierarchy at which code is permitted to define its own types.

Type

Value Type

Reference Type

Built-in Value Types

Enumerations

User-defined value types

Interface Types

Pointer Types

Self-describing Types

Arrays

Class Types

Delegates

User-defined Reference types

Boxed Value Types

Common Language Specification

CLS works with CTS to ensure language interoperability. CLS is a set of minimum standards that all compilers targeting .NET must support.

For ex, IL is case sensitive, However,VB.NET is not case sensitive. The CLS works around this by indicating the CLS-complaint code should not expose any two names that differ only in their case. There fore, VB.NET code can work with CLS complaint code

CLS works in two ways. First, it means that individual compilers do not have to be powerful enough to support the full features of .NET – this should encourage the development of compilers for other programming languages that target. .NET second, it provides a guarantee that, it restrict your classes to only exposing CLS complaint features, then it is guaranteed that code written in any other complaint language can use your classes.

Error handling through the use of exceptions

Use of attributes

Reference : Dilip Kumar Jena ( https://mstechexplore.wordpress.com )

Advertisements

One thought on “DOT NET 4.0 – The significance of .NET and C#

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s