object oriented programming using C#
I will start with an introduction to what is object oriented programming, how to write simple classes, creating objects etc.
What is a 'class' ?
In modern object oriented programming, large computer programs are divided into several 'classes'. Typically, a large project will have several hundred classes. A class represents an entity in a program. For example, if you are doing a small program called calculator, you will typically have a single (or more) class called 'Calculator' (you can give any name for your class). The class will have several 'methods', that will do the functionality of the class.
So, your calculator may have methods like the following:
Add()
Subtract()
Multiply()
Divide()
Here is a sample calculator class, written in C# :
using System;
public class Calculator
{
public int Add(int value1, int value2)
{
return value1 + value2;
}
public int Subtract(int value1, int value2)
{
return value1 - value2;
}
public int Multiply(int value1, int value2)
{
return value1 * value2;
}
public int Divide(int value1, int value2)
{
return value1 / value2;
}
}
Classes and objects
[To be added.]
Object model in .NET
[To be added.]
Hello World Application using C#
wanna learn C# ??
I will guide you through step by step process to create your first sample .NET application. All our sample code will be using C# syntax. Readers are suggested to stick to this new elegant language, than going back to your favorite VB style.
Hello World Application using C#
Let us get started the traditional way, with a 'Hello World' application. We hope you all have Visual Studio.NET installed on your computer. If you have VS.NET, goto the menu option File > New > Project. Select 'Visual C# projects' and choose the project template 'Console Application'. This will create a default
A simple C# program would look like the following.
using System;
public class Hello
{
public static void Main (string[] args)
{
Console.WriteLine("Hello C# World");
}
}
When you create a new Console Application, it will create a default class and you can just insert one line of code into it:
Console.WriteLine("Hello C# World");
Now compile and run your first program by pressing Ctrl + F5. You will see the following result :
> Hello C# World
You are done! You got your first C# program successfully running.
If you do not have VS.NET, you may use any editor (including notepad) to create your first C# program. Create a new file with the name sample.cs and type the C# code shown. Now go to the command prompt and navigate to the folder where you have the .NET framework installed. Compile your csharp file by using the command 'csc':
csc c:\samples\sample.cs
csc is the C# compiler. The above command will produce the output file sample.exe. You can run the sample.exe and you will see the output from the program.
Analyzing your first program
See the first line of code :
using System;
"System" is a namespace and the "using" directive says that all classes in the "System" namespace can be used in this class without using the fully qualified name. In our class, "Console" is a class in the namespace "System". To use this class you have to actually write : System.Console.WriteLine ("...");
But the using System; directive on top of the class allows us to use the class without including the namespace. So, you can now simply write :
Console.WriteLine("...");
If you are familiar with Object Oriented Programming, you might not need more explanation for the next line - declaring a class.
public static void Main (string[] args) - is the Main method, which is the starting point of the application.
string[] args is the list of arguments that are passed to this application. (In our case, we are not passing any command line parameters).
Console.WriteLine("...") is another line of important code. Console is a class, part of .NET class library included in System namespace. WriteLine is a method part if this class and used to print output to the default Console.
return ;)
word pubblisher test
From now , I’m trying put some ASP.net 2 articles here so please visit here in few days ….