C# VARIABLE:-

 C# VARIABLE:-


-variable is name of location where user can store different type date element.


-there are following types of variables used in c#:-

1)numerical variable - int

2)decimal variable  - double

3)character variable - char

4)string variable - string 

5)boolean variable (true/false)- bool/boolean


EXAMPLE:-


int a;

double b;

char c;

string city;

bool a;


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace Basicvariable

{

    class Program

    {

        static void Main(string[] args)

        {

            int a = 10;

            Console.WriteLine(a);

            Console.ReadKey();




        }

    }

}



2)

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace Basicvariable

{

    class Program

    {

        static void Main(string[] args)

        {

            int a = 10;

            Console.WriteLine(a);

            Console.WriteLine("The value of A " + a);

            Console.ReadKey();




        }

    }

}



USER INPUT VARIABLE:-(numerical input)


-in c# programming all types of input is used to ReadLine method.(in place of prompt line)

-in c# accepting all types numerical data with the help of int.Parse()


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace Basicvariable

{

    class Program

    {

        static void Main(string[] args)

        {

            int age;

            Console.WriteLine("Enter your age");

            age = int.Parse(Console.ReadLine());

            Console.WriteLine(age);

            Console.ReadKey();


        }

    }

}




HOW TO INPUT DECIMAL DATA:-


-all types of decimal data is to be input with the help of double.Parse()


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace Basicvariable

{

    class Program

    {

        static void Main(string[] args)

        {

            double cost;

            Console.WriteLine("Enter your cost");

            cost = double.Parse(Console.ReadLine());

            Console.WriteLine("Your cost is" + cost);

            Console.ReadKey();

        }

    }

}



HOW TO INPUT STRING DATA VALUE:-


-in string data value can not used any types parse statement

-string data value directly used ReadLine statement.


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace Basicvariable

{

    class Program

    {

        static void Main(string[] args)

        {

            string name;

            Console.WriteLine("Enter your Name");

            name = Console.ReadLine();

            Console.WriteLine("Your name is " + name);

            Console.ReadKey();        

        }

    }

}


Comments

Popular posts from this blog

HTML FORMS

condition management IF, ELSE, ELSEIF

HTML NOTES