Friday, 29 August 2014

Addition of two numbers in C sharp

using System;
class Program
{
    static void Main()
    {
        // addition of two numbers
        int a, b, sum;
        Console.WriteLine("Enter the value of a:");
        a = int.Parse(Console.ReadLine());
        Console.WriteLine("Enter the value of b:");
        b = int.Parse(Console.ReadLine());
        sum = a + b;
        Console.WriteLine("The sum of {0} & {1} is {2}",a,b, sum);
        Console.ReadLine();
    }
}

Addition of two numbers in C sharp
Output

how to print data types from variables in Csharp

using System;
class Program
{
    static void Main()
    {
        // how to print data types from variables 

        var i = 10;

        Console.WriteLine(i.GetType());
        var k = 23.1565;
        Console.WriteLine(k.GetType());
        var s = "panduraju";
        Console.WriteLine(s.GetType());
        var m = 3.156f;
        Console.WriteLine(m.GetType());
        var n = 3.14m;
        Console.WriteLine(n.GetType());
        Console.ReadLine();
    }
}


how to print data types from variables in Csharp
Output

Ascii Character in C#

using System;
class Program
{
    static void Main()
    {
        //converting char to int
        int i;
        Console.WriteLine("Enter any Number:");
        i = int.Parse(Console.ReadLine());
        char c = Convert.ToChar(i);
        Console.WriteLine(c);
        Console.ReadLine();


        //converting int to char
        char k;
        Console.WriteLine("Enter any Char:");
        k = char.Parse(Console.ReadLine());
        int m = Convert.ToInt32(k);
        Console.WriteLine(m);
        Console.ReadLine();

    }


}

How to Convert Char to Int
output


How to Convert Char to Int and Vice Versa in C#

using System;
class Program
{
    static void Main()
    {
        //converting char to int
        int i;
        Console.WriteLine("Enter any Number:");
        i = int.Parse(Console.ReadLine());
        char c = Convert.ToChar(i);
        Console.WriteLine(c);
        Console.ReadLine();


        //converting int to char
        char k;
        Console.WriteLine("Enter any Char:");
        k = char.Parse(Console.ReadLine());
        int m = Convert.ToInt32(k);
        Console.WriteLine(m);
        Console.ReadLine();

    }


}

How to Convert Char to Int
output