Example1


Programming to Read Integer values
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CABasics
{
    class ClsExample3
    {
        static void Main()
        {
            Console.WriteLine("Enter Your name");
            string s = Console.ReadLine();
            Console.WriteLine("Your name is" + s);
            Console.Read();
        }
    }
}


output:-

Data type conversion


There are Three Methods available for type Conversion:-



1)Syntax:-



          Convert.ToTarget Type Class(“Value”)   --- value

Ex:- Convert.ToInt32(“9”)      --       9        --       Integer
          Convert.ToInt64(“9”)    --       9        --       Long
          Convert.ToInt16(“9”)    --       9        --       Short
          Convert.ToDouble(“9”) --       9.0     --       Double

2)Syntax:-

          TargetTypeClass.parse(“value”)       -- value

Ex:-   Int32.pares(“9”)     --       9
          Int64.parse(“9”)     --       9
          Int16.parse(“9”)     --       9
          Double.parse(“9”)   --       9.0

3)Syntax:-

          TargetType.parse(“value”)      --       Value

Ex:-   int.parse(“9”)         --       9
          long.parse(“9”)      --       9
          short.parse(“9”)     --       9
          double.parse(“9”)   --       9.0



Programming to Read Integer values



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CABasics
{
    class ClsExample4
    {
        static void Main()
        {
            int a, b, c;
            Console.WriteLine("Enter two numbers");
            a = Convert.ToInt32(Console.ReadLine());
            b = Convert.ToInt32(Console.ReadLine());
            c = a + b;
            Console.WriteLine("sum of two numbers is " + c);
            Console.ReadLine();
        }
    }
}


 
















   
  output:-







No comments:

Post a Comment