KamranCSharp - whereIstand.com

Wednesday, May 28, 2008

1. Intro to ASP.NET and .Net Platform

META TAG Generator

Technology Blogs - BlogCatalog Blog Directory

Search Engine Optimization - AddMe

Submit Your Site To The Web's Top 50 Search Engines for Free!


AddThis Feed Button

My Zimbio
KudoSurf Me!




Chapter 1
Intro to ASP.NET and .NET Platform

Microsoft .NET Framework is a new computing platform for developing
distributed applications. It's an object-oriented framework for defining application, and
one of the most exciting web development technologies on the market today.
ASP.NET is a server side technology for developing web applications based on the
Microsoft .NET Framework.

Early in 2002 Microsoft released new technology for Internet development called ASP.NET.
ASP.NET is a new version of Classic ASP(Active Server Page). It continues to offer flexiblity in terms of language support, range of simple scripting languages, several fully-fledged programming languages. Development in ASP.NET required not only an understanding of HTML and web design, but also a firm grasp of the concepts of object oriented programming and development. When you learn programming in the .NET Framework, you can use your skills in developing different types of applications such as desktop applications, Web applications, and Web services.

.NET Framework is desinged to be object-oriented from the ground up. Before we go further
with web applications, you should know just a few terms such as Class, Inheritance, Namespace, and so on. This will be important right from the beginning.

Classes

A Class is a reference type that encapsulates data (such as constants and fields) and defines its behavior using programming constructs such as methods, properties, contrctors, and events.

Some beginners don't care about understanding it clearly so I think they will have a hard time learning C#.

A CLASS is nothing more than a blueprint of on object. And an object is nothing more than a
"virtual" representation of a CLASS. And when we say Instantiate and object or class, we mean to create the object in memory.

Lets look at a real world example. ( This is also the very first example I learned. )

The class will be a Book
Like anty blueprint, it will contain the attributs of the object it describes. So every book has a name or title, an author, and number of pages.
Class Book
Title
Author
Pages

If I were to instantiate a book( create one ) that class definination ( or blueprint for the object)
requires you to provide the Title, Author and Pages, for that book object.

class Book
{
string m_Title;
string m_Author;
string m_Pages;
}

Inheritance
Inheritance simply means, reusing the interface of the base class. It allows you to create new types based on types that already exist. The original type is called base class, and the inherited class is called a derived class.

Now, this example which I am about to show was taken from codeproject.com, but I have
tried to simplify even more.

When you derive a class from a base class, the derived class will inherit all members of the base class except constructors, though whether the derived class would be able to access those members would depend upon the accessibility of those members in the base class. C# gives us polymorphism through inheritance. Inheritance-based polymorphism allows us to define methods in a base class and override them with derived class implementations. Thus if you have a base class object that might be holding one of several derived class objects, polymorphism when properly used allows you to call a method that will work differently according to the type of derived class the object belongs to.

Now lets take a look at the following class, this will be our base class.
Guys, reading this will not do any good, untill you dont actually do the examples.

1. Open Visual Studio 2005.
2. Click on Create Project.
3. Click on Visual C#, then click on "Console Application".
4. After the console application open, right click on the bold letters "ConsoleApplication"
5. From the menu after you right click it, select "Add". Then from drop down list, select class.
6. Then change the name from Class.cs, to Car.cs.

Car.cs will be our base class, here we go now.

using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Car
{
public Car()
{
Console.WriteLine("Car constructor");
}
public void Feature()
{
Console.WriteLine("Car has sports tires");
}
public void Speed()
{
Console.WriteLine("Car is Fast");
}
public virtual void Door()
{
Console.WriteLine("Car has 2 doors");
}
}

Now lets see how we can derive another class from this base class.

1. Now let save this, and lets click on your "Program.cs".


using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Honda : Car
{
public Honda()
{
Console.WriteLine("Honda constructor");
}
public new void Feature()
{
Console.WriteLine("Honda has sports tires");
}
public override void Door()
{
Console.WriteLine("Honda has 2 doors");
}

On the bottom, try this code.


static void Main(string[] args)
{
Car c1 = new Car();
c1.Feature();
c1.Speed();
c1.Door();

// Output
Car constructor
Car has sports tires
Car is Fast
Car has 2 doors
}
}
}

Now, let try this code.


static void Main(string[] args)
{
Car c2 = new Honda();
c2.Feature();
c2.Speed();
c2.Door();

// Output

Car constructor
Honda constructor
Car has sports tires
Car is Fast
Honda has 2 doors
}
}
}

We have an object type Car, but we are now references an object of type Honda. Base class
constructor getting called first followed by the derived class contructor.
Now when we call Door(), we find that the derived class method has got called. This is because in the base class the method is prototyped as public virtual void Door() and in the derived class we have overridden it by using public override void Sing().

So, now you guys have just a little idea as far as what Inheritance is.

Namespace:

As ASP.NET is part of the .NET Framework, we have access to all the goodies that are built into
the form of the .NET Framework Class Library. So, when we have to use a feature that .NET
provides, we only have to find a namespace into our ASP.NET page. Once we have done that, we can make use of the .NET classes in that namespace to achieve our own ends.

For example, if we wanted to access a database from a page, we would import the name that contains classes for the purpose, so in this case I would use " System.Data.SqlClient ".

Guys after you do the examples provided, and read up on this article, you would want to practice a little more before you move on to Chapter 2. Obviously, you are not an expert at this point, but a little patience will come with a greater reward.


By KamranCsharp

1 comments:

Anonymous said...

This was a nice article, I am taking c# course in Virginia, so atleast the concept is clear. But, I would still like to see more examples.

Thanks....

Technology News