Skip to content

Instantly share code, notes, and snippets.

@rozer007
Created November 23, 2021 08:29
Show Gist options
  • Save rozer007/35615e05081c7d72708192aadbbf8676 to your computer and use it in GitHub Desktop.
Save rozer007/35615e05081c7d72708192aadbbf8676 to your computer and use it in GitHub Desktop.
Introduction to C#
Q1) How to assigned a number as a decimal in c#?
ans: To assigned a number as decimal we need to use the 'm' with the number.ie decimal dec = 1.2m;
For double we need to use 'd' with the number e.g double d = 1.2d;
Q2) What is the difference between double and decimal ?
ans: double is 64-bit floating-point number whereas Decimal is a 128-bit floating-point number and have higher precision.
eg. Console.WriteLine(1m/3); //in decimal
Console.WriteLine(1d/3); // in double
0.3333333333333333333333333333 //decimal
0.333333333333333 //double
Q3) Differnce between var and dynamic type ?
ans: var is defined at compile time and once a data type is assigned ,it can't be change.Whereas decimal is defined at runtime and the
data type can be changed even after the declaration.
Q4) How to take integer as input from the user ?
ans: We should change the input taken in string to integer using int.Parse() function.
eg. int a=int.Parse(Console.ReadLine());
Q1. How to take a input in c# :
a) Console.writline()
b) Console.Readline()
c) Console.Readall()
d) Console.ReadLine()
ans: d) Console.ReadLine()
Q2) Which of the following are not datatypes of c# :
a) int
b) bool
c) numbers
d) decimal
ans: c) numbers
Q3) How can we find the max range of a datatype ?
a) maxRange()
b) Max()
c) MaxValue()
d) Maxvalue()
ans: c) MaxValue()
Q4) what will be the output of this statement :
var pep="hello pepcoder"
pep=2010
Console.WriteLine(pep);
a) hello pepcoder
b) 2010
c) error
d) none of the above
ans: c)error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment