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


Monday, 28 July 2014

How to Reading and Writing to Console in Csharp

Interactive Programs in Csharp

Writing and Reading in Console Window

Console.ReadLine();

Console.WriteLine();


   
    
using System;
public class Hello1
{
    public static void Main(String[] args)

    {
        // This is For Printing a message in Console.
        Console.WriteLine("How to Read and Write to Console ");


        // This is For Reading a string (Text) from user given as input as FirstName
        string Firstname = Console.ReadLine();

        // This is For Printing FirstName in Console.
        Console.WriteLine("user Entered First Name: {0}",Firstname );

        // This is For Reading a string (Text) from user given as input as LastName
        string Lastname = Console.ReadLine();
        // This is For Printing LastName in Console.
        Console.WriteLine("user Entered LastName: {0}",Lastname);
        Console.ReadLine();
    }    
 

Output

How to Reading and Writing to Console in Csharp

 



Tuesday, 22 July 2014

Simple C# Program

Using System Declaration

The namespace declaration, using System,indicates that you are using the System namespace.
A Namespace is used to organize your code and is collection of classes, interfaces, structs, enums and delegates.

   
    
 Using System;
 Class Program
{
static Void Main()
{
Console.WriteLine("Welcome to C# Training");

}

}
       
 

Output

Three Methods to get the output
1. Go to Vistual Studio
2. On the Top Menu bar find the Debug Menu
3. Click on Start Debugging or Start Without Debugging
4. Now Get the output.