Saturday, March 6, 2010

Introduction to C#

Introduction

Microsoft Corporation, developed a new computer programming language C# ( pronounced as C-Sharp). C# is simple, modern, object oriented and type safe programming language derived from C and C++. C# is a purely object oriented language like as Java. It has been designed to support the key features of .NET framework.
Like Java, C# is a descendant language of C++ which is descendant of C language.




Features of C#

* Simplicity: C# code does not contain header files. All code is written inline.
* Consistent behavior: C# introduced a unified type system which eliminates the problem of varying ranges of integer types. All types are treated as objects and developers can extend the type system simply and easily.
* Modern Programming Language: C# supports number of modern features, such as Automatic Garbage Collection, Error Handling features, Modern Debugging features, Robust Security.
* Pure Object Oriented Programming Language: In C#, everything is treated as an object. There are no global functions, variable and constants.
* Type Safety: Type Safety promotes robust programming. eg. All objects are initialized to zero dynamically,automatic checking of the array (out of bound and etc.)

# Program 1

We are starting with our first C#.NET Program.

using System;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a, b, c;
a = 10;
b = 20;
c = a + b;
Console.WriteLine("the answer = " + c);

}
}
}

# Program 2

Program to input 2 numbers and calculate the sum.

using System;

namespace ConsoleApplication2
{
class Test1
{
static void Main(string[] args)
{
//how to input data from keyboard
//Console.ReadLine() this always input data in string format
// how to convert string data to integer or double
//int a=Convert.ToInt32(Console.ReadLine());
int a, b, c;
Console.WriteLine("Enter the values of a");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the values of b");
b = Convert.ToInt32(Console.ReadLine());

c = a + b;
Console.WriteLine("The asnwer =" + c);
}

}
}

# Program 3

Program to Calculate Simple interest.


using System;

namespace ConsoleApplication2
{
class Test2
{
static void Main(string[] args)
{
double amt, rate, time, Interest;
string name;
Console.WriteLine("Enter the Name ");
name = Console.ReadLine();
Console.WriteLine("Amount ");
amt = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Rate ");
rate = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Time ");
time = Convert.ToDouble(Console.ReadLine());
Interest= (amt * rate * time)/100;
Console.WriteLine("The Interest = " + Interest);
}
}
}

For next tutorial Click the following link:

http://dotnettutions2.blogspot.com