Saturday, 9 May 2015

Factorial in C#

In general maths factorial of a number means a result of multiplying a sequence started with the number and end to 1 in descending order like factorial of 5 is 5*4*3*2*1=120.

In C# the code also works on this logic. In our example we are taking number input from the user. You just take a look and try it by yourself.


using System;
namespace Factorial
{
    class Program
    {
        static void Main(string[] args)
        {
            int a,fact=1;
            a = int.Parse(Console.ReadLine());
            for (int i = 1; i <= a; i++)
            {
                fact = fact * i;
            }
            Console.WriteLine("The factorial of "+a+" is "+fact);
            }
    }

}

Wednesday, 4 February 2015

Hello world in C#

According to the tradition we will start our programming in c# with "Hello world". As suggested we have to write our code on visual studio. Their are some steps before our programming starts
  1. Select file.
  2. New Project.
  3. Select Console Application from the project dialog.
After clicking OK your visual studio will create a new project including a file 'Program.cs'.
Now screen should look something like this.





We have to write our code within the the set of { } appearing after line static void Main (string[] args). The code will be:

Console.WriteLine("Hello, World!");
Console.ReadLLine();





After writing the code press clt+F5. The compiler will generate a black screen having output. 


Saturday, 31 January 2015

Boxing and Unboxing

Boxing.

In c# programming language by Boxing we mean to converting a value type to a type object or to the interface type implemented same value type. CLR wraps the value inside the system.object and store it in the garbage-collected heap. Boxing is an implicit conversion.

The example of boxing is as below:


int a = 12;
object val = a;
//The above line is boxing variable a ant its value.


Unboxing.

Unboxing is an explicit conversion from the type to a value type or from an interface type to a value type that implements the interface. An unboxing  operation is consist of checking the object instance to make sure that it is a boxed value of given value type and copying the the instance to value type variable.

The example of unboxing is as below:

int a = 12;
object val = a;    //Boxing.
int w =(int) val;       //Unboxing.

Thursday, 29 January 2015

Introduction to C# Programming Language

C# is a simple, general purpose, modern, component oriented, object oriented language having some concept from other programming language, mostly from java. It was developed by Microsoft within its .NET initiative and later approved as a standard by Ecma (ECMA-334) and ISO (ISO/IEC 23270:2006) appeared in 2000.The most recent version is C# 5.0, which was released on August 15, 2012.

 C# is used in combination with the .NET framework. That's why application written in C#, requires the .NET framework to be installed on the computer running the application. C# does not offer global variance and function. Every thing is wrapped in classes even if you want to print a single string or integer you need a class for it which inherits the system object class.

C# can be written with any text editor, like Windows Notepad, and then compiled with the C# Command line compiler, csc.exe, which comes with the .NET framework. Mostly uses an IDE(Integrated Development Environment) and Microsoft also provide some other option.
Visual Studio is their flagship, which can use to work on every possible aspect of .Net Framework having its own various versions. But the visual studio is not cheap and very advanced for the hobby programmers.

After some time Microsoft introduce Express Version targeting hobby programmer with .NET Framework 2.0. Express Version is free of cost and just fine for the learning programmers.

I highly recommend you to Download Visual Studio Express Edition of C# from the following link: http://www.visualstudio.com/en-us/products/visual-studio-community-vs.



Ref:
1.www.visualstudio.com
2.www.csharp.net-tutorials.com
3.www.wikipedia.org.