Friday, May 18, 2007

Understanding C# .NET

What is C#?
C# (pronounced C-Sharp) is a new programming language introduced with the Microsoft .NET framework and is no doubt the language of choice in .NET environment. It was first created in the late 1990's as part of Microsoft’s whole .NET strategy. It is a whole new language free of backward compatibility curse and a whole bunch of new, exciting and promising features. It is an Object Oriented Programming language, which at its core, has similarities with Java, C++ and VB.
In fact, C# combines the power & efficiency of C++, simple & clean OO design of Java, and code simplification of Visual Basic. Like Java, C# also does not allow multiple inheritance and use of pointers (in safe and managed code) while it does provide garbage memory collection at runtime, type and memory access checking. But, contrary to java, C# keeps the different useful concepts of C++ like operator overloading, enumerations, pre-processor directives, pointers (in unmanaged and un-safe code), function pointers (in the form of delegates), also promises to have template support (with the name of generics) in next versions. Like VB it also supports the concepts of properties (context sensitive accessor to fields). In addition to this, C# comes up with some new/exciting features like reflections, attributes, marshalling, remoting, threads, streams, data access with ADO.NET, etc. C# programming language is designed from the scratch keeping in mind the Microsoft.Net environment. MS.Net (and thus C#) programs runs on top of the Common Language Runtime (CLR), which provides the runtime support to them.

Define C#?
C# is a simple, modern, object-oriented, and type-safe programming language derived from C and C++.

What can you do with C#?
Using the .NET libraries, you can write all types of internet applications, including HTTP connections, e-mail, and sockets programming.
You can implement .NET web services and create Windows Forms applications.
C# will allow you to use COM objects as well as create your own components.
You can even program ASP.NET and create ADO.NET datasets with C#.This is a rich programming language in which you can do anything you set your mind to.

What are the different types of .NET Applications that you can create Using C#?
Creating ASP.NET Application: creating Web pages with dynamic content. An ASP page is basically an HTML file with embedded chunks of server-side VBScript or JavaScript. When a client browser requests an ASP Page, the Web-server delivers the HTML portions of the page, processing the server-side scripts as it comes to them.
XML Web Services:
Creating Windows Forms
Windows Controls
Windows Services: is a program designed to run in the background in Windows NT/2000/XP/2003. Services are useful where you want the program to be running continuously and ready to respond to events without having been explicitly started by the user.

General Comments about C# Syntax:
Most statements end in a semicolon (;)
Can continue over multiple lines without needing a continuation characters such as underscore (in VB)
Statements can be joined into blocks using curly braces {}
Single-line comments begin with two forward slash characters
Multi-line comments begin with a slash and an asterisk (/*) and end with the same combination reversed (*/)

What is .NET Framework?
The .NET Framework has two main components: the common language runtime and the .NET Framework class library.You can think of the runtime as an agent that manages code at execution time, providing core services such as memory management, thread management, and remoting, while also enforcing strict type safety and other forms of code accuracy that ensure security and robustness.The class library, is a comprehensive, object-oriented collection of reusable types that you can use to develop applications ranging from traditional command-line or graphical user interface (GUI) applications to applications based on the latest innovations provided by ASP.NET, such as Web Forms and XML Web services.

What are the new features of Framework 1.1 ?
1. Native Support for Developing Mobile Web Applications
2. Enable Execution of Windows Forms Assemblies Originating from the InternetAssemblies originating from the Internet zone—for example, Microsoft Windows® Forms controls embedded in an Internet-based Web page or Windows Forms assemblies hosted on an Internet Web server and loaded either through the Web browser or programmatically using the System.Reflection.Assembly.LoadFrom() method—now receive sufficient permission to execute in a semi-trusted manner. Default security policy has been changed so that assemblies assigned by the common language runtime (CLR) to the Internet zone code group now receive the constrained permissions associated with the Internet permission set. In the .NET Framework 1.0 Service Pack 1 and Service Pack 2, such applications received the permissions associated with the Nothing permission set and could not execute.
3. Enable Code Access Security for ASP.NET ApplicationsSystems administrators can now use code access security to further lock down the permissions granted to ASP.NET Web applications and Web services. Although the operating system account under which an application runs imposes security restrictions on the application, the code access security system of the CLR can enforce additional restrictions on selected application resources based on policies specified by systems administrators. You can use this feature in a shared server environment (such as an Internet service provider (ISP) hosting multiple Web applications on one server) to isolate separate applications from one another, as well as with stand-alone servers where you want applications to run with the minimum necessary privileges.
4. Native Support for Communicating with ODBC and Oracle Databases
5. Unified Programming Model for Smart Client Application DevelopmentThe Microsoft .NET Compact Framework brings the CLR, Windows Forms controls, and other .NET Framework features to small devices. The .NET Compact Framework supports a large subset of the .NET Framework class library optimized for small devices.
6. Support for IPv6The .NET Framework 1.1 supports the emerging update to the Internet Protocol, commonly referred to as IP version 6, or simply IPv6. This protocol is designed to significantly increase the address space used to identify communication endpoints in the Internet to accommodate its ongoing growth. http://msdn.microsoft.com/netframework/technologyinfo/Overview/whatsnew.aspx

Is .NET a runtime service or a development platform?
Ans: It's both and actually a lot more. Microsoft .NET includes a new way of delivering software and services to businesses and consumers. A part of Microsoft.NET is the .NET Frameworks. The .NET frameworks SDK consists of two parts: the .NET common language runtime and the .NET class library. In addition, the SDK also includes command-line compilers for C#, C++, JScript, and VB. You use these compilers to build applications and components. These components require the runtime to execute so this is a development platform.

What are the languages aside from C# are interoperable with the .NET?
1. VB 2005
2. VC++ 2005
3. VJ* 2005
4. Scripting languages
i. JScript.NET
ii. ASP.NET
5. COM and COM+

.NET Security
.NET can really excel in terms of security mechanisms provided by Windows because it can offer code-based security, whereas the Windows only really offers role-based security.
· Role-based security: is based on the identity of the a/c under which the process is running (that is, who owns and is running the process)
· Code-based security: is based on what the code actually does and on how much the code is trusted. The CLR is able to inspect code before running it in order to determine required security permission. The importance of the code-based security is that it reduces the risks associated with running code of dubious origin

Application domains
Application domains are an important innovation in .NET and are designed to ease the overhead involved when running applications that need to be isolated from each other, but that also need to be able to communicate with each other. The classic ex of this is a Web server application, which may be simultaneously responding to a number of browser requests.
Application domains are designed as a way of separating components without resulting in the performance problems associated with passing data between processes.

Error Handling with Exceptions
The .NET Framework is designed to facilitate handling of error conditions using the same mechanism, based on exceptions

NET Framework Classes
One of the biggest benefits of writing managed code is that you get to use the .NET base class library.
The .NET base classes are a massive collection of managed code classes that allow you to do almost any of the tasks that were previously available through the Windows API.

Namespaces
Namespaces are the way that .NET avoids name clashes between classes. They are designed to avoid the situation in which you define a class to represent a customer..
A namespace is no more than a grouping of data types, but it has the effect that the names of all data types within a namespace automatically get prefixed with the name of the namespace. It is also possible to nest namespaces within each other.
The .NET base classes are in a namespace called System. The base class Array is in this namespace, so its full name is System.Array. .NET requires all types to be defined in a namespace.

No comments: