How to take input from USER'S in C#:-


To take input from User's in C# We will using Console.ReadLine()  It will return data in String pattern which can be easily typecast into different datatype.


User's Input based on Different Datatype:-

1)    int a =  int.Parse(Console.ReadLine())

2)    float b = float.Parse(Console.ReadLine())

3)    String s =   Console.ReadLine()

4)    char ch = char.Parse(Console.ReadLine())


Complete Program Explanation to take input from users.

using System;   //namespace which contains predefined classes
class SI
{

  public static void Main()
  {
      float p,r,t,si;
      Console.WriteLine("Enter value for P");
      p=float.Parse(Console.ReadLine());
      Console.WriteLine("Enter value for R");
      r=float.Parse(Console.ReadLine());
      Console.WriteLine("Enter value for T");
      t=float.Parse(Console.ReadLine());
      si= (p*r*t)/100;
   
      Console.WriteLine("result is " + si);
  }


}




//  float.Parse() is the predefine method which is used to convert float String to float value.



                         




Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post