This blog is about the dotnet.all types of codes,news about dotnet including asp.net,vb.net,c# and know about new dotnet technology.programing in asp.net,vb.net,c#, ajax, AJAX tech support for .net and discuss the new technology in dotnet.ncluding asp.net,vb.net,c# and know about new dotnet technology.programing in asp.net,vb.net,c#, ajax, AJAX tech support for .net and discuss the new technology in dotnet.asp.net programming,dot net programming,dotnet programs,dotnet source code,source code.

Free Hosting

Free Hosting

Friday, February 8, 2008

.NET Languages

The common language runtime defines a common runtime for all .NET languages. Although C# and VB.NET are the two flagship languages of .NET, any language that targets the common language runtime is on equal footing with any other language. In this section we'll talk about the features that the .NET languages offer.

Classes and Objects:
The common language runtime deals in managed types. The runtime can load types, execute methods of a type, and instantiate objects of a type. Although the common language runtime supports several forms of types, such as classes, interfaces, structures, enumerations, and delegates, all of these forms ultimately are represented as classes at the lowest levels of the runtime. And although the common language runtime does support exporting entry points that are not enclosed in a type, at least two languages (VB.NET and C#) do not support entry points outside of a type definition.

Although in OOP it is possible to invoke some class methods without objects, the most common use of classes is to produce objects. In the common language runtime, an object is an instance of exactly one class. The operations that may be performed on an object are determined by the object's class. The amount and type of storage used by the object is determined by the object's class. In essence, the class acts as a factory or template for objects that belong to that class.

The common language runtime supports instantiating objects based on a class. Each programming language exposes this functionality somewhat differently. In C# and VB.NET, for example, the new keyword is used to create a new object of a given class, as shown in the following two code snippets:

C#
IceCream ic = new IceCream();
ic.MakeACone();

VB

Dim ic as new IceCream();
ic.MakeACone ()

Classes are defined in C# and in VB.NET using the class keyword. The following code shows sample classes in each:

C# Class

public class IceCream
{
string strFlavor = "Chocolate";
public void MakeACone()
{
System.Console.Write( "I have made a cone. My flavor is "
);
System.Console.WriteLine( strFlavor + "." );
}
}

VB.NET Class

Public Class IceCream
Dim strFlavor as string = "Chocolate"
Public Sub MakeACone()
System.Console.Write("I have made a cone. My flavor is ")
System.Console.WriteLine(strFlavor & ".")
End Sub
End Class

Constructors

Unless the programmer takes special steps, the fields of the class will be set to a well-known initial value when an object is created. Numeric types are set to zero, and objects are set to null (C#) or Nothing (VB). You can change the values that are used by writing a constructor. A constructor is a special method that is called automatically to set the class's fields to a programmer-determined state prior to the first use of the object (or class).

Constructors are called when a new object is created, before the new operator returns the reference to the new object. Constructors may accept parameters, and they may be overloaded based on parameter count or type. The following code shows typical constructors:

C#

public class IceCream
{
private int i = 5;
public IceCream()
{
System.Console.WriteLine( "This is delicious!" );
}
}


VB.NET

Public Class IceCream
Sub New()
System.Console.WriteLine( "This is delicious!" )
End Sub
End Class

Namespaces
Namespaces
in the .NET runtime are used to organize classes and types into separate spaces. You define namespaces using the namespace keyword, as shown in the following code:

namespace Rick
{
public class MyClass
{
public static void DoSomething()
{
}
}
}

The using keyword in C# promotes elements in other namespaces into the global namespace. The following code shows an example of referencing two separate namespaces with the using keyword:

using Rick;
using System;


MyClass.DoSomething();
Console.WriteLine( "Just called DoSomething()" );



0 comments:

dotnet(.Net) Project Source code Downloads and Tutorials

Email Subscrption



Enter your email address:

Delivered by FeedBurner

Feedburner Count

Unique Visitor

Design by araba-cı | MoneyGenerator Blogger Template by GosuBlogger