0% found this document useful (0 votes)
19 views7 pages

Dot Net

Download as txt, pdf, or txt
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 7

5. Select the correct differences between char and varchar data types?

i. varchar is non unicode and char is unicode character data type


ii. char is ‘n’ bytes whereas varchar is actual length in bytes of data entered in
terms of storage size
iii. varchar is variable in length and char is the fixed length string
iv. For varchar, if a string is less than the maximum length then it is stored in
verbatim without any extra characters while for char if a string is less than the
set length it is padded with extra characters to equalize its length to given
length
a) i, iii, iv
b) ii, iii, iv
c) i, ii, iv
d) iii, iv
View Answer

Answer: d
Explanation: By definition.

6. Which is the String method used to compare two strings with each other?
a) Compare To()
b) Compare()
c) Copy()
d) ConCat()
View Answer

Answer: a
Explanation: CompareTo() used to compare two strings by taking the length of
strings in considerations.

7. What will be the output of the following C# code?

static void Main(string[] args)


{
string s1 = "Delhi";
string s2;
s2 = s1.Insert (6, "Jaipur");
Console.WriteLine(s2);
}
a) DelhJaipuri
b) Delhi Jaipur
c) Delhi
d) DelhiJaipur
View Answer

Answer: d
Explanation: Insert method() of string class used to join two strings s1 and s2.
Output :
DelhiJaipur

12. What will be the output of the following C# code?

string s1 = " I AM BEST ";


string s2;
s2 = s1.substring (5, 4);
Console.WriteLine (s2);
a) AM BEST
b) I AM BES
c) BEST
d) I AM
View Answer

Answer: c
Explanation: Substring() of string class used to extract substrings from given
string. In the given substring condition, it extracts a substring beginning at 5th
position and ending at 4th position.

14. Verbatim string literal is better used for?


a) Convenience and better readability of strings when string text consist of
backlash characters
b) Used to initialize multi-line strings
c) To embed a quotation mark by using double quotation marks inside a verbatim
string
d) All of the mentioned
View Answer

Answer: d
Explanation: By definition.

15. Why strings are of reference type in C#.NET?


a) To create string on stack
b) To reduce the size of string
c) To overcome problem of stackoverflow
d) None of the mentioned

Ans d

2. Storage location used by computer memory to store data for usage by an


application is?
a) Pointers
b) Constants
c) Variable
d) None of the mentioned
View Answer

Answer: c
Explanation: ‘Variables’ are essential locations in memory of computer that are
reserved for storing data used by an application. Each variable is given a name by
programmer and hence assigned a value. The name assigned to variable then used in
C# code to access value assigned to variable.

Q
static void Main(string[] args)
{
int a = 5;
int b = 10;
int c;
Console.WriteLine(c = a-- - ++b);
Console.WriteLine(b);
Console.ReadLine();
}
a) -7, 10
b) -5, 11
c) -6, 11
d) 15, 11
View Answer

Answer: c
4. What will be the output of the following C# code?

class Program
{
static void Main(string[] args)
{
int i ;
for ( i = 0; i < 5; i++)
{
int j = 0;
j += i;
Console. WriteLine(j);
}
Console. WriteLine(i);
Console. ReadLine();
}
}
a) 0, 1, 2, 3, 4, 5, 6
b) 0, 1, 2, 3, 4, 5
c) 0, 1, 2, 3, 4
d) 0, 1, 2, 3
View Answer

Answer: b
Explanation: None.
Output:

CONVERSION AND DATA TYPE


1. What is the need for ‘Conversion of data type’ in C#?
a) To store a value of one data type into a variable of another data type
b) To get desired data
c) To prevent situations of runtime error during change or conversion of data type
d) None of the mentioned
View Answer

Answer: c
Explanation: By Definition.

5. The subset of ‘int’ data type is __________


a) long, ulong, ushort
b) long, ulong, uint
c) long, float, double
d) long, float, ushort
Ans long, ulong, uint

2. Types of ‘Data Conversion’ in C#?


a) Implicit Conversion
b) Explicit Conversion
c) Implicit Conversion and Explicit Conversion
d) None of the mentioned

Ans Implicit Conversion and Explicit Conversion


6. Type of Conversion in which compiler is unable to convert the data type
implicitly is?
a) ushort to long
b) int to uint
c) ushort to long
d) byte to decimal
View Answer

Answer: b
Explanation: ‘int’ is 32 bit signed integer whereas ‘uint’ is 32 bit unsigned
integer. Range of int is larger than uint. So, the compiler cannot implicitly
convert from larger data type to smaller data type.

8.
static void Main(string[] args)
{
int a = 76;
char b;
b = (char)a;
Console.WriteLine(b);
Console.ReadLine();
}
a) Compiler will generate runtime error
b) Conversion is explicit type
c) Compiler will urge for conversion from ‘integer’ to ‘character’ data type
d) None of the mentioned
View Answer

Answer: b
Explanation: Since, given conversion is of explicit type as one data type is in
integer and other is in ‘char’. Compiler is needed to make a clear distinction
between both type of data types and hence, explicitly one need to specify data type
as compiler is unable to make automatic conversion.
Output : L

Arithmetic Operators

3. What will be the output of the following C# code?

static void Main(string[] args)


{
int a, b, c, x;
a = 80;
b = 15;
c = 2;
x = a - b / (3 * c) * ( a + c);
Console.WriteLine(x);
Console.ReadLine();
}
a) 78
b) -84
c) 80
d) 98
View Answer

Answer: b
4. Correct order of priorities are:
a) ‘/’ > ‘%’ > ‘*’ > ‘+’
b) ‘/’ > ‘*’ > ‘%’ > ‘+’
c) ‘*’ > ‘/’ > ‘%’ > ‘+’
d) ‘%’ > ‘*’ > ‘/’ > ‘+’
View Answer

Answer: c

6. What will be the output of the following C# code?

static void Main(string[] args)


{
int b= 11;
int c = 7;
int r = 5;
int e = 2;
int l;
int v = 109;
int k;
int z,t,p;
z = b * c;
t = b * b;
p = b * r * 2;
l = (b * c) + (r * e) + 10;
k = v - 8;
Console.WriteLine(Convert.ToString(Convert.ToChar(z)) + " " +
Convert.ToString(Convert.ToChar(t)) + Convert.ToString(Convert.ToChar(p)) +
Convert.ToString(Convert.ToChar(l)) + Convert.ToString(Convert.ToChar(v)) +
Convert.ToString(Convert.ToChar(k)));
Console.ReadLine();
}
a) My Name
b) My nAme
c) My name
d) Myname
View Answer

Answer: c
Explanation: Solving the expression l = (b * c) + (r * e) + 10. While from left to
right the parentheses are given preference first.
Step 1 : b * c is evaluated first inside first parentheses.
Step 2 : r * e is evaluated second on right side of first addition symbol.
Step 3 : After evaluating both parentheses 10 is added to value of both.
Output : My name.

10. The correct way of incrementing the operators are:


a) ++ a ++
b) b ++ 1
c) c += 1
d) d =+ 1
View Answer

Answer: c
Explanation: This += is known as short hand operator which is same as variable =
variable +1. Similarly, a-= 1 is a = a-1, a*=1 is a = a * 1. They are used to make
code short and efficient.

Relational And Logical Operator


10. The correct way of incrementing the operators are:
a) ++ a ++
b) b ++ 1
c) c += 1
d) d =+ 1
View Answer

Answer: c
Explanation: This += is known as short hand operator which is same as variable =
variable +1. Similarly, a-= 1 is a = a-1, a*=1 is a = a * 1. They are used to make
code short and efficient.

8. What will be the output of the following C# code?

static void Main(string[] args)


{
int m = 10, n = 5, p = 20;
bool b1 = m * p / n <= p * n / m ;
int l = p - 2 * m;
bool b2 = l == 0;
int z = Convert.ToInt32(b2);
int k = Convert.ToInt32(b1);
Console.WriteLine(k);
Console.WriteLine(z);
}
a) 0 0
b) 1 0
c) 0 1
d) 1 1
View Answer

Answer: c
Explanation: Solving the expression for b1 tests the condition for either true or
false result in ‘0’. Similarly, for ‘b2’ ‘l’ on solving gives ‘0’. So, condition is
true for bool b2 as 0 == 0. Hence, k = 0 and z = 1.
Output :
0 1.

10. What will be the output of the following C# code?

static void Main(string[] args)


{
int a = 8, b = 6, c = 10;
int d = a * c * 2 / Convert.ToInt32(Math.Pow ((c - b), 2));
if (d == (c = Convert.ToInt32(Math.Sqrt (a * a + b * b))) && c == 10)
{
Console.WriteLine("figure is hypotenuse");
}
else
{
Console.WriteLine("figure is square");
}
}
a) Figure is square
b) Figure is hypotenuse
c) False
d) None of the mentioned
Ans b

You might also like