Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 89

1. How many Bytes are stored by ‘Long’ Data type in C# .net?

a) 8
b) 4 9. Which is the correct way of defining and initializing an array of 3 integers?
c) 2 a) int[] a={78, 54};
d) 1 b)
2. Choose “.NET class” name from which data type “UInt” is derived? int[] a;
a) System.Int16 a = new int[3];
b) System.UInt32 a[1] = 78;
c) System.UInt64 a[2] = 9;
d) System.UInt16 a[3] = 54;
3. Correct Declaration of Values to variables ‘a’ and ‘b’? c)
a) int a = 32, b = 40.6; int[] a;
b) int a = 42; b = 40; a = new int{78, 9, 54};
c) int a = 32; int b = 40; d)
d) int a = b = 42; int[] a;
4. What will be the error in the following C# code? a = new int[3]{78, 9, 54};
1. Static Void Main(String[] args)
2. { 10. Choose selective differences between an array in c# and array in other
3. const int m = 100; programming languages.
4. int n = 10; a) Declaring array in C# the square bracket([]) comes after the type but not
5. const int k = n / 5 * 100 * n ; after identifier
6. Console.WriteLine(m * k); b) It is necessary to declare size of an array with its type
7. Console.ReadLine(); c) No difference between declaration of array in c# as well as in other
8. } programming languages
a) ‘k’ should not be declared constant d) All of the mentioned
b) Expression assigned to ‘k’ should be constant in nature Basic Operation on Strings
c) Expression (m * k) is invalid 1. Which of the following string() method are used to compare two strings
d) ‘m ‘ is declared in invalid format with each other?
4. What will be the error in the following C# code? a) CopyTo()
1. Static Void Main(String[] args) b) Copy()
2. { c) Compare()
3. const int m = 100; d) CompareTo()
4. int n = 10;
5. const int k = n / 5 * 100 * n ; 2. Choose the base class for string() method:
6. Console.WriteLine(m * k); a) System.Array
7. Console.ReadLine(); b) System.char
8. } c) System.String
a) ‘k’ should not be declared constant d) None of the mentioned
b) Expression assigned to ‘k’ should be constant in nature
c) Expression (m * k) is invalid 3. What will be the output of the following C# code?
d) ‘m ‘ is declared in invalid format advertisement
5. Arrange the following data type in order of increasing magnitude sbyte, 1. static void Main(string[] args)
short, long, int. 2. {
a) long < short < int < sbyte 3. string s1 = " Cshr ";
b) sbyte < short < int < long 4. string s2 = s1.Insert(3 , " a ");
1
c) short < sbyte < int < long 5. string s3 = s2.Insert(5 , " p ");
d) short < int < sbyte < long 6. for (int i = 0;i < s3.Length; i++)
6. Which data type should be more preferred for storing a simple number like 7. Console.WriteLine(s3[i]);
35 to improve execution speed of a program? 8. Console.ReadLine();
a) sbyte 9. }
b) short a) Cshar
c) int b) CsharP
d) long c) Csharp
7. Which Conversion function of ‘Convert.TOInt32()’ and ‘Int32.Parse()’ is d) Cshrap
efficient?
i) Int32.Parse() is only used for strings and throws argument exception for 4. Which of the following statement is correct about a string in C#.NET?
null string a) The System.Array class is used to represent a string
ii) Convert.Int32() used for data types and returns directly '0' for null string b) A string has a zero-based index
a) ii c) A number cannot be represented in the form of a string
b) Both i, ii d) A string is mutable because it can be modified once it has been created
c) i
d) None of the mentioned 5. What will be the output of the following C# code?
8. Correct way to assign values to variable ‘c’ when int a=12, float b=3.5, int 1. static void Main(string[] args)
c; 2. {
a) c = a + b; 3. string s1 = "Hello";
b) c = a + int(float(b)); 4. string s2 = "hello";
c) c = a + convert.ToInt32(b); 5. if (s1 == s2)
d) c = int(a + b); 6. Console.WriteLine("Equal");
9. What will be Correct Set of C# Code for given data ‘a’ and ‘b’ to print 7. else
output for ‘c’ as 74? 8. Console.WriteLine("Unequal");
a) 9. if (s1.Equals (s2))
1. int a = 12; 10. Console.WriteLine("Equal");
2. float b = 6.2f; 11. else
3. int c; 12. Console.WriteLine("Unequal");
4. c = a / b + a * b; 13. Console.ReadLine();
5. Console.WriteLine(c); 14. }
b) a)
1. int a = 12; Equal
2. float b = 6.2f; Unequal
3. int c; b)
4. c = a / convert.ToInt32(b) + a * b; Unequal
5. Console.WriteLine(c); Equal
c) c)
1. int a = 12; Equal
2. float b = 6.2f; Equal
3. int c; d)
4. c = a / convert.ToInt32(b) + a * convert.ToInt32(b); Unequal
5. Console.WriteLine(c); Unequal
d)
1. int a = 12;
2
2. float b = 6.2f; 6. What will be the output of the following C# code?
3. int c; 1. static void Main(string[] args)
4. c = convert.ToInt32(a / b + a * b); 2. {
5. Console.WriteLine(c); 3. string s1 = "Hello" + " I " + "Love" + " ComputerScience ";
10. Does the output remain same or different for both cases? 4. Console.WriteLine(s1);
i) 5. Console.ReadLine();
1. char l ='k'; 6. }
2. float b = 19.0f; a) HelloILoveComputerScience
3. int c; b) Hello I Love ComputerScience
4. c = (l / convert.ToInt32(b)); c) Compile time error
5. Console.Writeline(c); d) Hello
ii)
1. char l ='k'; 7. Correct way to find if contents of two strings are equal?
2. float b = 19.0f; a) if (s1 = s2)
3. int c; b) if (s1 != s2)
4. c = Convert.ToInt32(l / b); c) if (strcmp (s1 ,s2))
5. console.writeline(c); d) if ( s1 is s2)
a) Yes
b) No 8. Which of the following statements are correct?
11. Default Type of number without decimal is? a) String is value type
a) Long Int b) String literals can contain any character literal including escape
b) Unsigned Long sequences
c) Int c) The equality operators are defined to compare values of string objects as
d) Unsigned Int well as references
d) All of the mentioned
12. What will be the output of the following C# code?
1. static void Main(string[] args) 9. Which of these operators can be used to concatenate two or more String
2. { objects?
3. float a = 10.553f; a) +
4. long b = 12L; b) +=
5. int c; c) &
6. c = Convert.ToInt32(a + b); d) ||
7. Console.WriteLine(c);
8. } 10. The Method use to remove white space from a string?
a) 23.453 a) Split()
b) 22 b) Substring()
c) 23 c) Trim()
d) 22.453 d) TrimStart()
## Floating and Decimal Data Types String Class with Description
1. Select a convenient declaration and initialization of a floating point 1. What is the String in C# meant for?
number: a) Variable
a) float somevariable = 12.502D b) Character Array
b) float somevariable = (Double) 12.502D c) Object
c) float somevariable = (float) 12.502D d) Class
d) float somevariable = (Decimal)12.502D
3
2. What does the term ‘immutable’ means in term of string objects?
2. Number of digits upto which precision value of float data type is valid? a) We can modify characters included in the string
a) Upto 6 digit b) We cannot modify characters contained in the string
b) Upto 8 digit c) We cannot perform various operation of comparison, inserting, appending
c) Upto 9 digit etc
d) Upto 7 digit d) None of the mentioned

advertisement 3. To perform comparison operation on strings supported operations are


3. Valid Size of float data type is? ____________
a) 10 Bytes a) Compare()
b) 6 Bytes b) Equals()
c) 4 Bytes c) Assignment ‘==’ operator
d) 8 Bytes d) All of the mentioned

4. Correct way to define a value 6.28 in a variable ‘pi’ where value cannot be advertisement
modified? 4. What will be the output of the following C# code?
a) #define pi 6.28F 1. static void Main(string[] args)
b) pi = 6.28F 2. {
c) const float pi = 6.28F 3. string s1 = "Hello I Love Csharp ";
d) 4. Console.WriteLine(Convert.ToChar( (s1.IndexOf('I') -
const float pi s1.IndexOf('l')) * s1.IndexOf('p'));
pi = 6.28F 5. Console.ReadLine();
6. }
Note: Join free Sanfoundry classes at Telegram or Youtube a) I
5. What will be the correct set of C# code to display the value of given b) Hello I
variable ‘c’ as ‘25.302’. c) Love
a) d) H
1. float a = (double) 12.502f;
2. float b = 12.80f; Note: Join free Sanfoundry classes at Telegram or Youtube
3. float c; 5. Correct way to convert a string to uppercase using string class method()?
4. c = (float) a + b; a) Upper()
5. Console.Writeline(c); b) ToUpper()
6. Console.ReadLine(); c) Object.ToUpper()
b) d) None of the mentioned
1. float a = 12.502D;
2. float b = 12.80f; 6. What will be the output of the following C# code?
3. float c; 1. static void Main(string[] args)
4. c = a + b; 2. {
5. Console.WriteLine(c); 3. String obj = "hello";
6. Console.ReadLine(); 4. String obj1 = "world";
c) 5. String obj2 = obj;
1. double a = 12.502; 6. Console.WriteLine (obj.Equals(obj2) + " " +
2. float b = 12.802f; obj2.CompareTo(obj) );
3. float c; 7. Console.ReadLine();
4. c = (float)a + b; 8. }
4
5. Console.WriteLine(c); a) True True
6. Console.ReadLine(); b) False False
d) c) True 0
1. double a = (float) 12.502f; d) False 1
2. float b = 12.80f;
3. float c; 7. What will be the output of the following C# code?
4. c = a + b; 1. static void Main(string[] args)
5. Console.WriteLine(c); 2. {
6. Console.ReadLine(); 3. String obj = "hello";
4. String obj1 = "world";
5. String obj2 = obj;
6. Minimum and Maximum range of values supported by ‘float’ data type 6. Console.WriteLine(obj + " " + obj1);
are? 7. string s = obj + " " + obj1;
a) 1.5 * 10-40 to 3.4 * 1038 8. Console.WriteLine(s.Length);
b) 1.5 * 10-45 to 3.4 * 1030 9. Console.ReadLine();
c) 1.5 * 10-45 to 3.4 * 1038 10. }
d) 1.5 * 10-45 to 3.4 * 1037 a)
hello world
7. Select appropriate difference between decimal, float and double data type 10
in C#? b)
i) Float and Double are floating binary point types while decimal is a floating hello world
decimal point type. 6
ii) Precision difference for float is '7' digit for double is '15' to '16' digit and for c)
decimal is '28' to '29' digits. hello world
iii) Some values which cannot be exactly represented hence for those values 11
float and double are more appropriate. d)
a) i hello world
b) i, iii 5
c) i, ii, iii
d) ii, iii
8. Why does a float variable stop incrementing at number ‘16777216’ in the 8. What will be the output of the following C# code?
following C# code? 1. static void Main(string[] args)
1. float a = 0 ; 2. {
2. while (true) 3. String obj = "hello";
3. { 4. String obj1 = "world";
4. a++; 5. String obj2 = obj;
5. if (a > 16777216) 6. string s = obj+" "+obj1;
6. break; 7. Console.WriteLine(s.IndexOf('r'));
7. } 8. Console.ReadLine();
a) Sign and Exponent for ‘16777217’ is same as for ‘16777216’ 9. }
b) Mantissa is different for ‘16777216’ and ‘16777217’ a) 7
c) Sign and Exponent for ‘16777217’ is different from ‘16777216’ b) 8
d) None of the mentioned c) 9
9. What will be the output of the following C# code? d) 10
1. static void Main(string[] args)
5
2. { 9. What will be the output of the following C# code?
3. int x = 1; 1. static void Main(string[] args)
4. float y = 2. 4f; 2. {
5. short z = 1; 3. String obj = "hello";
6. Console. WriteLine((float) x + y * z - (x + = (short) y) ); 4. String obj1 = "world";
7. Console. ReadLine(); 5. String obj2 = obj;
8. } 6. string s = obj + " " + obj1;
a) 0.4000004 7. Console.WriteLine(s.Substring(6 ,5));
b) 0.4000023 8. Console.ReadLine();
c) 0.0400021 9. }
d) 0.4000001 a) hello
10. A float occupies 4 bytes. If the hexadecimal equivalent of these 4 bytes b) orld
are A, B, C and D, then when this float is stored in memory in which of the c) world
following order do these bytes gets stored? d) o world
a) ABCD
b) DCBA 10. What will be the output of the following C# code?
c) 0 * ABCD 1. static void Main(string[] args)
d) Depends on big endian or little endian architecture 2. {
11. The Default value of Boolean Data Type is? 3. String obj = "hello";
a) 0 4. String obj1 = "worn";
b) True 5. String obj2 = obj;
c) False 6. Console.WriteLine(obj + " " + (obj1.Replace('w' ,'c')));
d) 1 7. Console.ReadLine();
8. }
12. What will be the output of the following C# code? a) hello hello
1. public static void Main(string[] args) b) hello worn
2. { c) hello corn
3. double ZERO = 0; d) hello
4. Console.WriteLine("RESULT OF DIVISION BY ZERO IS :{0}", (0 /
ZERO)); Comparison of Strings
5. Console.ReadLine(); o1. Which of these methods of class String is used to compare two String
6. } objects for their equality?
a) 1 a) equals()
b) exception argument is thrown b) Equals()
c) NaN c) isequal()
d) 0 d) Isequal()
13. Which of the following format specifiers is used to print hexadecimal
values and return value of output as Octal equivalent in C#? 2. Which of these methods is used to compare two strings such that after
a) %hx for small case letters and %HX for capital letters comparison output returns different integer values as (0 for false, 1 for
b) %x for small case letters and %X for capital letters true)?
c) No ease of doing it. C# don’t provides specifier like %x or %O to be used a) Equals ()
with ReadLine() OR WriteLine(). We have to write our own function b) == operator
d) %Ox for small case letters and %OX for capital letters c) Compare()
### Char Types and String Literals d) None of the mentioned
1. What is the Size of ‘Char’ datatype?
6
a) 8 bit 3. Which of these methods of class String is used to check whether a
b) 12 bit substring exists at the beginning of the particular string?
c) 16 bit a) StartsWith()
d) 20 bit b) EndsWith()
2. What will be the output of the following C# code? static void Main(string[] c) Starts()
args) d) ends()
{
char c = 'g'; advertisement
string s = c.ToString(); 4. Which of these methods returns the string such that some characters
string s1 = "I am a human being" + s; which are specified to be removed from the end of strings are removed from
Console.WriteLine(s1); string by mentioning the number of characters to be removed?
Console.ReadLine(); a) Trim()
} b) Remove()
a) I am a human being c c) TrimEnd()
b) I am a human beingg d) Split()
c) I am a human being g
d) I am a human being 5. What is the value returned by function compareTo() if the invoking string
3. Given is the code of days(example:”MTWTFSS”) which I need to split is less than the string compared?
and hence create a list of days of week in strings( example:”Monday”, a) zero
“Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”). A set b) value less than zero
of code is given for this purpose but there is the error occurring in that set of c) value greater than zero
code related to the conversion of char to strings. Hence, Select a C# code to d) none of the mentioned
solve the given error.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Note: Join free Sanfoundry classes at Telegram or Youtube
Participate Now! 6. Which of these data type values is returned by equals() method of String
static void Main(string[] args) class?
{ a) char
var days = "MTWTFSS"; b) int
var daysArray = days.ToCharArray().Cast<string>().ToArray(); c) boolean
for (var i = 0; i < daysArray.Length; i++) d) all of the mentioned
{
switch (daysArray[i]) 7. What will be the output of the following C# code?
{ 1. class Program
case "M": 2. {
daysArray[i] = "Monday"; 3. static void Main(string[] args)
break; 4. {
case "T": 5. String c = "i love Csharp";
daysArray[i] = "Tuesday"; 6. bool a;
break; 7. a = c.StartsWith("I");
case "W": 8. Console.WriteLine(a);
daysArray[i] = "Wednesday"; 9. Console.ReadLine();
break; 10. }
case "R": 11. }
daysArray[i] = "Thursday"; a) true
break; b) false
7
case "F": c) 0
daysArray[i] = "Friday"; d) 1
break;
case "S": 8. What will be the output of the following C# code?
daysArray[i] = "Saturday"; 1. class Program
break; 2. {
case "U": 3. static void Main(string[] args)
daysArray[i] = "Sunday"; 4. {
break; 5. String s1 = "I love You";
} 6. String s2 = s1;
} 7. Console.WriteLine((s1 == s2) + " " + s1.Equals(s2));
daysArray[daysArray.Length - 1] = "and " + daysArray[daysArray.Length - 8. Console.ReadLine();
1]; 9. }
Console.WriteLine(string.Join(", ", daysArray)); 10. }
} a) true true
a) var daysArray = new List<String>(); b) false false
b) var daysArray = days.Select(c =>dayMapping[c]).ToArray(); c) true false
c) var daysArray = days.ToCharArray().Select(c =>c.Tostring()).ToArray(); d) false true
d) var daysArray = days.Select<String>();
9. What will be the output of the following C# code?
4. What will be the output of the following C# code?static void Main(string[] 1. class Program
args) 2. {
{ 3. static void Main(string[] args)
{ 4. {
var dayCode = "MTWFS"; 5. String []chars = {"z", "x", "y", "z", "y"};
var daysArray = new List<string>(); 6. for (int i = 0; i < chars.Length; ++i)
var list = new Dictionary<string, string> 7. for (int j = i + 1; j < chars.Length; ++j)
{ {"M", "Monday"}, {"T", "Tuesday"}, {"W", "Wednesday"}, 8. if(chars[i].CompareTo(chars[j]) == 0)
{"R", "Thursday"}, {"F", "Friday"}, {"S", "Saturday"}, 9. Console.WriteLine(chars[j]);
{"U", "Sunday"} 10. Console.ReadLine();
}; 11. }
for (int i = 0,max = dayCode.Length; i < max; i++) 12. }
{ a) zx
var tmp = dayCode[i].ToString(); b) xy
if (list.ContainsKey(tmp)) c) zy
{ d) yz
daysArray.Add(list[tmp]);
} 10. What will be the output of the following C# code?
} 1. String a = "Csharp";
Console.WriteLine(string.Join("\n ", daysArray)); 2. String b = "CSHARP";
} 3. int c;
a) Monday, Tuesday, Wednesday, Friday, Saturday, Sunday 4. c = a.CompareTo(b);
b)Monday 5. Console.WriteLine(c);
Tuesday a) 0
Wednesday b) 1
8
Friday c) -2
Sunday d) -1
c)Monday Searching and Modifying Strings
Tuesday 1. Which of these methods of class String is used to separate a substring
Wednesday from a String object?
Friday a) substring()
Saturday b) Substring()
d) Monday, Tuesday, Wednesday, Friday, Saturday c) SubString()
d) None of the mentioned
5. Select the correct differences between char and varchar data types?
i. varchar is non unicode and char is unicode character data type 2. What will be the output of the following C# code?
ii. char is ‘n’ bytes whereas varchar is actual length in bytes of data entered 1. static void Main(string[] args)
in terms of storage size 2. {
iii. varchar is variable in length and char is the fixed length string 3. String a = "Ilove";
iv. For varchar, if a string is less than the maximum length then it is stored in 4. String b = "CSHARP";
verbatim without any extra characters while for char if a string is less than the 5. b = string.Concat(a, ' ', b);
set length it is padded with extra characters to equalize its length to given 6. Console.WriteLine(b);
length 7. Console.ReadLine();
a) i, iii, iv 8. }
b) ii, iii, iv a) IloveCSHARP
c) i, ii, iv b) I loveCSHARP
d) iii, iv c) Ilove
6. Which is the String method used to compare two strings with each other? d) Ilove CSHARP
a) Compare To()
b) Compare() 3. Which of these methods of class are used to remove the leading and
c) Copy() backward whitespaces?
d) ConCat() a) startsWith()
7. What will be the output of the following C# code?static void Main(string[] b) trim()
args) c) Trim()
{ d) doTrim()
string s1 = "Delhi";
string s2; Note: Join free Sanfoundry classes at Telegram or Youtube
s2 = s1.Insert (6, "Jaipur"); 4. What will be the output of the following C# code?
Console.WriteLine(s2); 1. static void Main(string[] args)
} 2. {
a) DelhJaipuri 3. String a = "Ilove";
b) Delhi Jaipur 4. String b = "CSHARP";
c) Delhi 5. b = string.Concat(a,' ',b);
d) DelhiJaipur 6. string d = b.TrimStart('I', 'l', 'o', 'H');
8. For two strings s1 and s2 to be equal, which is the correct way to find if 7. Console.WriteLine(d);
the contents of two strings are equal? 8. Console.ReadLine();
a) if(s1 = s2) 9. }
b)int c; a) Ilove CSHARP
c = s1.CompareTo(s2); b) love CSHARP
c) if (s1 is s2) c) ve CSHARP
9
d) if(strcmp(s1, s2)) d) ve CSARP

9. What will be the output of the following C# string? (Enter a String : 5. What will be the output of the following C# code?
BOMBAY).static void Main(string[] args) 1. static void Main(string[] args)
{ 2. {
string Str, Revstr = " "; 3. String c = " Hello Computer ";
int Length; 4. String a = c.Trim();
Console.Write("Enter A String : "); 5. Console.WriteLine("\"" + s + "\"");
Str = Console.ReadLine(); 6. }
Length = Str.Length - 1; a) ” Hello Computer ”
while (Length >= 0) b) “HelloComputer”
{ c) “Hello Computer”
Revstr = Revstr + Str[Length]; d) Hello Computer
Length --;
} 6. What will be the output of the following C# code?
Console.WriteLine("Reverse String Is {0}", Revstr); 1. static void Main(string[] args)
Console.ReadLine(); 2. {
} 3. String c = "Hello";
a) BOMBA 4. String a = c + "Bye";
b) YABMOB 5. Console.WriteLine(a);
c) BOMAYB 6. Console.ReadLine();
d) YABMO 7. }
a) “Hello Bye”
10. Select the appropriate set of C# code for conversion of string to hexa b) “HelloBye”
form. static void Main(string[] args) c) Hello Bye
{ d) HelloBye
string teststring = "MIKA@?&";
string hex = ConvertstringToHex(teststring, 7. What will be the output of the following C# code?
system.Text.Encoding.Unicode); 1. static void Main(string[] args)
Console.WriteLine(hex); 2. {
} 3. String c = "Hello";
a)static string ConvertstringToHex(string input, system.Text.Encoding 4. String a ;
encoding) 5. a = c.Replace('l', 'w');
{ 6. Console.WriteLine(a);
string Bytes = encoding.GetBytes(input); 7. Console.ReadLine();
string Builder sbBytes = new Builder sbBytes(); 8. }
for each (byte 'b' in StringBytes) a) Helloll
{ b) Hewlo
sBytes.AppendFormat("{0:x2}", b); c) Helwo
} d) Hewwo
return sbBytes.Tostring();
} 8. Which of the following statements is correct?
b) a) replace() replace() method replaces last occurrence of a character in
static string ConvertstringToHex(string input, system.Text.Encoding invoking strings with another character
encoding) b) replace() method replaces only first occurrence of a character in invoking
10
{ strings with another character
char[]string Bytes = encoding.GetBytes(input); c) replace() method replaces all occurrences of one character in invoking
string Builder sbBytes = new Builder sbBytes(StringBytes.Length*2); strings with another character
for each (byte 'b' in StringBytes) d) none of the mentioned
{
sBytes.AppendFormat("{0:X2}", b); 9. What will be the output of the following C# code snippet?
} 1. static void Main(string[] args)
return sbBytes.Tostring(); 2. {
} 3. String c = "Hello i love you";
c)public static string ConvertStringToHex(String input, 4. String a ;
System.Text.Encoding encoding) 5. a = c.Substring(12, 3);
{ 6. Console.WriteLine(a);
{ 7. Console.ReadLine();
Byte[] stringBytes = encoding.GetBytes(input); 8. }
StringBuilder sbBytes = new StringBuilder(stringBytes.Length * 2); a) ove
foreach (byte b in stringBytes) b) you
{ c) yo
sbBytes.AppendFormat("{0:X2}", b); d) love you
}
Console.WriteLine(sbBytes.ToString());//sbBytes.ToString()); 10. Which among the following is the correct way to find out the index of
return sbBytes.ToString(); second ‘s’ in the string “She sold her beauty in one night to someone else”?
} a)
} String a = "She sold her beauty in one night to someone else";
d) None of the mentioned int i;
i = a.SecondIndexOf("s");
11. Which of the following C# code is used for conversion of hex to string b)
form?static void Main(string[] args) String a = "She sold her beauty in one night to someone else";
{ int i, j;
string testString = "MIKA@?&^"; i = a.FirstIndexOf("s");
string normal = ConvertHexToString (hex, j = a.IndexOf("s", i + 1);
System.Text.Encoding.Unicode); c)
Console.WriteLine(normal); String a = "She sold her beauty in one night to someone else";
Console.ReadLine(); int i, j;
} i = a.IndexOf("s");
a)public static string ConvertHexToString(String hexInput, j = a.IndexOf("s", i + 1);
System.Text.Encoding encoding) d) None of the mentioned
{ Operation on Characters1. Which of these methods of the class String is
char[] numberChars = hexInput.Length; used to obtain length of String object?
byte[] bytes = new byte[numberChars / 2]; a) get()
for (int i = 0; i < numberChars; i += 2) b) Sizeof()
{ c) lengthof()
bytes[i / 2] = Convert.ToByte(hexInput.Substring(i, 0), 16); d) length()
}
return encoding.GetString(bytes); 2. Which of these methods is an alternative to getChars() that stores the
} characters in an array of bytes?
11
b)public static string ConvertHexToString(String hexInput, a) getBytes()
System.Text.Encoding encoding) b) GetByte()
{ c) giveByte()
int numberChars = hexInput.Length; d) Give Bytes()
byte[] bytes = new byte[numberChars / 2];
for (int i = 0; i < numberChars; i += 2) 3. Which of these methods can be used to convert all characters in a String
{ into a character array?
bytes[i / 2] = Convert.ToByte(hexInput.Substring(i, 2), 16); a) CharAt()
} b) getChars()
return encoding.GetString(bytes); c) TocharArray()
} d) All of the mentioned
c)public static string ConvertHexToString(String hexInput,
System.Text.Encoding encoding) advertisement
{ 4. What will be the output of the following C# code snippet?
string numberChars = hexInput.Length; 1. static void main(String args[])
byte[] bytes = new byte[numberChars]; 2. {
for (int i = 0; i &lt; numberChars; i += 2) 3. char chars[] = {'x', 'y', 'z'};
{ 4. String s = new String(chars);
bytes[i / 2] = Convert.ToByte(hexInput.Substring(i, 2), 16); 5. Console.WriteLine(s);
} 6. }
return encoding.GetString(bytes); a) x
} b) xy
d) None of the mentioned c) z
12. What will be the output of the following C# code? d) xyz
string s1 = " I AM BEST ";
string s2; 5. Choose the effective stringBuilder method which helps in producing
s2 = s1.substring (5, 4); output for the following C# code?
Console.WriteLine (s2); 1. static void Main(string[] args)
a) AM BEST 2. {
b) I AM BES 3. StringBuilder s = new StringBuilder("object");
c) BEST 4. s./*______*/("Oriented Language");
d) I AM 5. Console.WriteLine(s);
13. Correct statement about strings are? 6. Console.ReadLine();
a) a string is created on the stack 7. }
b) a string is primitive in nature 8. Output : objectOriented Language
c) a string created on heap a) Insert()
d) created of string on a stack or on a heap depends on the length of the b) Add()
string c) Append()
14. Verbatim string literal is better used for? d) Join()
a) Convenience and better readability of strings when string text consist of
backlash characters 6. What will be the output of the following C# code?
b) Used to initialize multi-line strings 1. static void Main(string[] args)
c) To embed a quotation mark by using double quotation marks inside a 2. {
verbatim string 3. string s = " i love you";
d) All of the mentioned 4. Console.WriteLine(s.IndexOf('l') + " " + s.lastIndexOf('o') + " " +
12
15. Why strings are of reference type in C#.NET? s.IndexOf('e'));
a) To create string on stack 5. Console.ReadLine();
b) To reduce the size of string 6. }
c) To overcome problem of stackoverflow a) 3 5 7
d) None of the mentioned b) 4 5 6
Initialization of Variables c) 3 9 6
1. What will be the output of the following C# code? d) 2 4 6
1. static void Main(string[] args)
2. { 7. Which of these methods of class String is used to extract all the
3. int a = 5; characters from a String object?
4. int b = 10; a) CHARAT()
5. int c; b) Remove()
6. Console.WriteLine(c = ++ a + b ++); c) charAt()
7. Console.WriteLine(b); d) Replace()
8. Console.ReadLine();
9. } 8. What will be the output of the following C# code snippet?
a) 11, 10 1. static void Main(string[] args)
b) 16, 10 2. {
c) 16, 11 3. string c = "hello";
d) 15, 11 4. string c1 = c.Remove(1);
5. Console.WriteLine(c1);
2. Storage location used by computer memory to store data for usage by an 6. Console.ReadLine();
application is? 7. }
a) Pointers a) ello
b) Constants b) h
c) Variable c) hell
d) None of the mentioned d) none of the mentioned

Subscribe Now: C# Newsletter | Important Subjects Newsletters 9. How is a string typically processed?
3. DIFFERENCE BETWEEN KEYWORDS ‘VAR’ AND ‘DYNAMIC’? a) On a character by character basis
a) ‘Var’ is introduced in C# (3.0) and ‘Dynamic’ is introduced in C# (4.0) b) On a string by string basis
b) ‘Var’ is a type of variable where declaration is done at compile time by c) Both On a character by character basis & On a string by string basis
compiler while ‘Dynamic’ declaration is achieved at runtime by compiler d) None of the mentioned
c) For ‘Var’ Error is caught at compile time and for ‘Dynamic’ Error is caught
at runtime 10. How to print \\ on the screen?
d) All of the mentioned a) Console.WriteLine(“\\”);
b) Console.WriteLine(“\\\”);
4. The following C# codes are? c) Console.WriteLine(“\\\\”);
1. 1. Myclass class; d) Console.WriteLine(“\\\\\\”);
2. Myclass class2 = null;
1. 2. int i; Public & Private Access Modifier1. Which of these is used as a default
2. int j = 0; specifier for a member of the class if no access specifier is used for it?
a) True for (1);False for (2) a) private
b) True for (2);False for (1) b) public
c) Both (1) and (2) are equivalents c) public, within its own class
13
d) Both (1) and (2) are not equivalents d) protected

5. What will be the output of the following C# code? 2. Which of these is used to access members of class before the object of
1. int a,b; that class is created?
2. a = (b = 10) + 5; a) public
a) b = 10, a = 5 b) private
b) b = 15, a = 5 c) static
c) a = 15, b = 10 d) protected
d) a = 10, b = 10
3. Which of these base classes are accessible to the derived class
6. What will be the output of the following C# code conversion? members?
1. static void Main(string[] args) a) static
2. { b) protected
3. char a = 'A'; c) private
4. string b = "a"; d) Shared
5. Console.WriteLine(Convert.ToInt32(a));
6. Console.WriteLine(Convert.ToInt32(Convert.ToChar(b))); advertisement
7. Console.ReadLine(); 4. What is the process by which we can control parts of a program that can
8. } access the members of a class?
a) 1, 97 a) Polymorphism
b) 97, 65 b) Abstraction
c) 65, 97 c) Encapsulation
d) 65, 1 d) Recursion

7. What will be the output of the following C# code? 5. What will be the output of the following C# code?
1. static void Main(string[] args) Note: Join free Sanfoundry classes at Telegram or Youtube
2. { 1. class sum
3. String name = "Dr.Gupta"; 2. {
4. Console.WriteLine("Good Morning" + name); 3. public int x;
5. } 4. private int y;
a) Dr.Gupta 5. public void math(int a, int b)
b) Good Morning 6. {
c) Good MorningDr.Gupta 7. x = a * 4;
d) Good Morning name 8. y = b;
9. }
8. What will be the output of the following C# code? 10. }
1. static void Main(string[] args) 11. class Program
2. { 12. {
3. int a = 5; 13. static void Main(string[] args)
4. int b = 10; 14. {
5. int c; 15. sum p = new sum();
6. Console.WriteLine(c = a-- - ++b); 16. p.math(12, 30);
7. Console.WriteLine(b); 17. Console.WriteLine(p.x + " " + p.y);
8. Console.ReadLine(); 18. Console.ReadLine();
9. } 19. }
14
a) -7, 10 20. }
b) -5, 11 a) 48, 30
c) -6, 11 b) 48, 0
d) 15, 11 c) 0, 0
d) Compile time error
9. What will be the output of the following C# code?
1. static void Main(string[] args) 6. What will be the output of the following C# code?
2. { 1. class sum
3. const int a = 5; 2. {
4. const int b = 6; 3. public int x;
5. for (int i = 1; i <= 5; i++) 4. public int y;
6. { 5. public int add (int a, int b)
7. a = a * i; 6. {
8. b = b * i; 7. x = a + b;
9. } 8. y = x + b;
10. Console.WriteLine(a); 9. return 0;
11. Console.WriteLine(b); 10. }
12. Console.ReadLine(); 11. }
13. } 12. class Program
a) 600, 720 13. {
b) Compile time error 14. static void Main(string[] args)
c) 25, 30 15. {
d) 5, 6 16. sum obj1 = new sum();
17. sum obj2 = new sum();
10. What will be the output of the following C# code? 18. int a = 2;
1. static void Main(string[] args) 19. obj1.add(a, a + 1);
2. { 20. obj2.add(5, a);
3. string Name = "He is playing in a ground."; 21. Console.WriteLine(obj1.x + " " + obj2.y);
4. char[] characters = Name.ToCharArray(); 22. Console.ReadLine();
5. StringBuilder sb = new StringBuilder(); 23. }
6. for (int i = Name.Length - 1; i >= 0; --i) 24. }
7. { a) 6, 9
8. sb.Append(characters[i]); b) 5, 9
9. } c) 9, 10
10. Console.Write(sb.ToString()); d) 3, 2
11. Console.ReadLine();
12. } 7. What will be the output of the following C# code?
a) He is playing in a grou 1. class math
b) .ground a in playing is He 2. {
c) .dnuorg a ni gniyalp si eH 3. public int a,b;
d) He playing a 4. public math(int i, int j)
Scope and Lifetime of Variables 5. {
g1. Choose the correct type of variable scope for the following C# defined 6. a = i;
variables. class ABC 7. b = j;
{ 8. }
15
static int m; 9. public void sum(math m)
int n; 10. {
void fun (int x , ref int y, out int z, int[] a) 11. m.a *= 2;
{ 12. m.b += 2;
int j = 10; 13. }
} 14. }
} 15. class Program
a) m = static variable, n = local variable, x = output parameter, y = reference 16. {
parameter, j = instance variable, z = output parameter, a[0] = array element 17. static void Main(string[] args)
b) m = static variable, n = instance variable, x = value parameter, y = 18. {
reference parameter, j = local variable, z = output parameter , a[0] = array 19. math t = new math(20, 10);
element 20. t.sum(t);
c) m = static variable, n = instance variable, x = reference parameter, y = 21. Console.WriteLine(t.a + " " + t.b);
value parameter, j = local variable, z = output parameter, a[0] = array 22. Console.ReadLine();
element 23. }
d) m = local variable, n = instance variable, x = reference parameter, y = 24. }
value parameter, j = static variable, z = output parameter, a[0] = array a) 10, 20
element b) 20, 10
advertisement2. What will be the output of the following C# code? c) 40, 12
class Program d) 5, 40
{
static void Main(string[] args) 8. Accessibility modifier defined in a class are?
{ a) public, private, protected
int i ; b) public, internal, protected internal
for (i = 0; i < 5; i++) c) public, private, internal, protected internal
{ d) public, private, protected, internal, protected internal
Console.WriteLine(i);
} 9. Choose the statements which are false in nature?
Console.ReadLine(); a) The base class member functions can access public member functions of
} derived class
} b) An object of a derived class cannot access private member of the base
a) 0, 1, 2, 3, 4, 5 class
b) 0, 1, 2, 3 c) Private members of the base class cannot be accessed by derived class
c) 0, 1, 2, 3, 4 member functions or objects of derived class
d) 0, 0, 0, 0, 0 d) None of the mentioned
3. What will be the output of the following C# code? class Program
{ 10. Which of these access specifiers must be used for main() method?
static void Main(string[] args) a) private
{ b) public
int i; c) protected
for ( i = 0; i < 5; i++) d) none of the mentioned
{ Use of Ref and Out Parameters
1. What will be the output of the following C# code?
} 1. class Program
Console. WriteLine(i); 2. {
16
Console. ReadLine(); 3. static void Main(string[] args)
} 4. {
} 5. int i = 5;
a) 0, 1, 2, 3, 4, 5 6. int j;
b) 0, 1, 2, 3, 4 7. method1(ref i);
c) 5 8. method2(out j);
d) 4 9. Console.writeline(i + " " + j);
10. }
4. What will be the output of the following C# code? class Program 11. static void method1(ref int x)
{ 12. {
static void Main(string[] args) 13. x = x + x;
{ 14. }
int i ; 15. static void method2(out int x)
for ( i = 0; i < 5; i++) 16. {
{ 17. x = 6;
int j = 0; 18. x = x * x;
j += i; 19. }
Console. WriteLine(j); 20. }
} a) 36, 10
Console. WriteLine(i); b) 10, 36
Console. ReadLine(); c) 0, 0
} d) 36, 0
}
a) 0, 1, 2, 3, 4, 5, 6 2. Statements about ‘ref’ keyword used in C#.NET are?
b) 0, 1, 2, 3, 4, 5 a) The ref keyword causes arguments to be passed by reference
c) 0, 1, 2, 3, 4 b) While using ‘ref’ keyword any changes made to the parameter in the
d) 0, 1, 2, 3 method will be reflected in the variable when control is passed back to the
5. What will be the output of the following C# code? calling method
static void Main(string[] args) c) Ref usage eliminates overhead of copying large data items
{ d) All of the mentioned
int i ;
for (i = 0; i < 5; i++) Sanfoundry Certification Contest of the Month is Live. 100+ Subjects.
{ Participate Now!
int j = 0; 3. What will be the output of the following C# code?
j += i; 1. static void main(string[] args)
Console. WriteLine(j); 2. {
} 3. int n = 1;
Console. WriteLine( i * j); 4. method(n);
Console. ReadLine(); 5. console.Writeline(n);
} 6. method1(ref n);
a) 0, 1, 6, 18, 40 7. console.Writeline(n);
b) 0, 1, 5, 20, 30 8. }
c) Compile time error 9. static void method(int num)
d) 0, 1, 2, 3, 4, 5 10. {
6. Scope of variable is related to definition of variable as: 11. num += 20;
17
i. Region of code within which variable value is valid and hence can be 12. console.writeline(num);
accessed. 13. }
ii. No, relation with region where variable is declared its value is valid in 14. static void method1(ref int num)
entire scope. 15. {
a) i 16. num += 20;
b) ii 17. console.writeline(num);
c) i, ii 18. }
d) None of the mentioned a)
1
7. What will be the output of the following C# code? class Program 1
{ 1
public static void Main(string[] args) 1
{ b)
int i = 100; 21
for (a = 0; a < 5; a++) 1
{ 21
int i = 200; 21
Console. WriteLine(a * i); c)
} 11
Console. ReadLine(); 21
} 21
} 11
a) 5, 10, 15, 20 d)
b) 0, 5, 10, 20 21
c) Compile time error 1
d) 0, 1, 2, 3, 4 21
8. Syntax for declaration and initialization of data variable is? 21
a) <data type><var_name> = <Value>;
b) <data type><var_name>; 4. Which method does following C# code explains?
c) <var_name><data type>; 1. static void Main(string[] args)
d) <var_name> = <value>; 2. {
3. int a = 10, b = 20;
9. What will be the output of the following C# code? class Program 4. method(ref a, ref b);
{ 5. console.writeline(a + " " + b);
public static void Main(string[] args) 6. }
{ 7. static void swap(ref int i, ref int j)
int i, j; 8. {
i = (j = 5) + 10; 9. int t;
Console. WriteLine(i); 10. t = i;
Console. WriteLine(j); 11. i = j;
Console. ReadLine(); 12. j = t;
} 13. }
} a) Call by reference
a) 15, 15 b) Call by value
b) 10, 5 c) Output parameter
18
c) 15, 5 d) parameter arrays
d) 10, 15
10. Choose effective differences between ‘Boxing’ and ‘Unboxing’. 5. What will be the output of the following C# code?
a) ‘Boxing’ is the process of converting a value type to the reference type 1. static void main(string[] args)
and ‘Unboxing’ is the process of converting reference to value type 2. {
b) ‘Boxing’ is the process of converting a reference type to value type and 3. int []arr = new int[]{ 1, 2, 3, 4, 5};
‘Unboxing’ is the process of converting value type to reference type 4. fun (ref arr);
c) In ‘Boxing’ we need explicit conversion and in ‘Unboxing’ we need implicit 5. for (int i = 0; i < arr.Length ; i++)
conversion 6. Console.WriteLine( arr[i] + " ");
d) Both ‘Boxing’ and ‘Unboxing’ we need implicit conversion 7. }
8. static void fun(ref int[]a)
11. Select differences between reference type and value type: 9. {
i. Memory allocated to ‘Value type’ is from heap and reference type is from 10. a = new int[6];
‘System. ValueType’ 11. a[3] = 32;
ii. Memory allocated to ‘Value type’ is from ‘System. ValueType’ and 12. a[1] = 24;
reference type is from ‘Heap’ 13. }
iii. Structures, enumerated types derived from ‘System. ValueType’ are a) 0, 0, 32, 0, 0, 0
created on stack, hence known as ValueType and all ‘classes’ are reference b) 0, 24, 0, 32, 0, 0
type because values are stored on heap c) 24, 0, 32, 0, 0, 0
a) i, iii d) 0, 0, 32, 0, 0, 0
b) ii, iii
c) i, ii, iii 6. What will be the output of the following C# code?
d) i 1. static void main(string[] args)
12. What will be the output of the following C# code? public static void 2. {
Main(string[] args) 3. int i;
{ 4. int res = fun (out i);
int i = 123; 5. console.writeline(res);
object o = i; 6. console.readline();
i = 456; 7. }
System. Console. WriteLine("The value-type value = {0}", i); 8. static int fun(out int i)
System. Console. WriteLine("The object-type value = {0}", o); 9. {
Console. ReadLine(); 10. int s = 1;
} 11. i = 7;
a) 123, 123 12. for (int j = 1; j <= i; j++ )
b) 456, 123 13. s = s * j;
c) 456, 456 14. return s;
d) 123, 456 15. }
a) 4490
13. What will be the output of the following C# code? public static void b) 5040
Main(string[] args) c) 5400
{ d) 3500
int i = 546;
object o = i; 7. What will be the output of the following C# code?
int n =(int) o; 1. static void Main(string[] args)
o = 70; 2. {
19
System. Console. WriteLine("The value-type value = {0}", n); 3. int a = 5;
System. Console. WriteLine("The object-type value = {0}", o); 4. int b = 0, c = 0;
Console. ReadLine(); 5. method (a, ref b, ref c);
} 6. Console.WriteLine(b + " " + c);
a) 546, 0 7. Console.ReadLine();
b) 546, 546 8. }
c) 546, 70 9. static int method(int x, int p, ref int k)
d) 70, 546 10. {
–Type Conversion in Expressions 11. p = x + x * x;
1. What is the need for ‘Conversion of data type’ in C#? 12. k = x * x + p;
a) To store a value of one data type into a variable of another data type 13. return 0;
b) To get desired data 14. }
c) To prevent situations of runtime error during change or conversion of data a) 30, 55
type b) 55, 30
d) None of the mentioned c) Compile time error
d) 0, 0
2. Types of ‘Data Conversion’ in C#?
a) Implicit Conversion 8. Keyword used to define call by reference parameter in C# .NET?
b) Explicit Conversion a) &
c) Implicit Conversion and Explicit Conversion b) out
d) None of the mentioned c) ref
d) &&
3. ‘Implicit Conversion’ follows the order of conversion as per compatibility of
data type as: 9. Select the correct match of parameter declaration.
a) float < char < int 1. static Void main(string[] args)
b) char < int < float 2. {
c) int < char < float 3. int a = 5;
d) float < int < char 4. int b = 6;
5. float c = 7.2f;
advertisement 6. math (ref a, ref b, ref c);
4. For the following C# code select the relevant solution for conversion of 7. Console.WriteLine(a + " " + b + " " + c);
data type. 8. }
1. static void Main(string[] args) 9. static int math(/*add parameter declaration */)
2. { 10. {
3. int num1 = 20000; 11. a += b;
4. int num2 = 50000; 12. b *= (int)c;
5. long total; 13. c += a * b;
6. total = num1 + num2; 14. return 0;
7. Console.WriteLine("Total is : " +total); 15. }
8. Console.ReadLine(); a) ref int a, int b, ref float c
9. } b) ref int a, ref float c, ref int b
a) Compiler will generate runtime error c) ref int a, ref int b, float c
b) Conversion is implicit type, no error generation d) ref int a, ref int b, ref float c
c) Specifying data type for conversion externally will solve the problem
d) None of the mentioned 10. Which statement is/are correct?
20
a) An argument passed to a ref parameter need not be initialized first
5. The subset of ‘int’ data type is __________ b) Variables passed as out arguments need to be initialized prior to being
a) long, ulong, ushort passed
b) long, ulong, uint c) To use a ref parameter, only the calling method must explicitly use the ref
c) long, float, double keyword
d) long, float, ushort d) None of the mentioned

6. Type of Conversion in which compiler is unable to convert the data type Use of Variable Number of Arguments
implicitly is? o1. The method in which large or variable number of arguments are handled
a) ushort to long is known as ________________
b) int to uint a) Value parameters
c) ushort to long b) Output parameters
d) byte to decimal c) Parameter arrays
d) None of the mentioned
7. Disadvantages of Explicit Conversion are?
a) Makes program memory heavier 2. The modifiers used to define an array of parameters or list of arguments
b) Results in loss of data is __________
c) Potentially Unsafe a) ref
d) None of the mentioned b) out
c) param
8. For the given set of C# code, is conversion possible? d) var
1. static void Main(string[] args)
2. { 3. What will be the output of the following C# code?
3. int a = 76; advertisement
4. char b; 1. static void Main(string[] args)
5. b = (char)a; 2. {
6. Console.WriteLine(b); 3. object[] a = {" 1 ", 4.0f, " harsh "};
7. Console.ReadLine(); 4. fun(a);
8. } 5. Console.ReadLine();
a) Compiler will generate runtime error 6. }
b) Conversion is explicit type 7. static void fun(params object[] b)
c) Compiler will urge for conversion from ‘integer’ to ‘character’ data type 8. {
d) None of the mentioned 9. for (int i = 0; i < b.Length - 1; i++)
10. Console.WriteLine(b[i] + " ");
9. What will be the output of the following C# code? 11. }
1. static void Main(string[] args) a) 1 4.0 harsh
2. { b) 1 4
3. float sum; c) 1 4 hars
4. int i; d) 1 4 harsh
5. sum = 0.0F;
6. for (i = 1; i <= 10; i++) 4. Which of the following statements are correct?
7. { a) C SHARP allows a function to have arguments with default values
8. sum = sum + 1 /(float)i; b) C SHARP allows a function to have variable number of arguments
9. } c) Params are used to specify the syntax for a function having arguments
10. Console.WriteLine("sum =" +sum); d) Omitting the return value type in method definition results into an
21
11. Console.ReadLine(); exception
12. }
a) 2.000 5. What will be the output of the following C# code?
b) 2.910 1. static void Main(string[] args)
c) 2.928 2. {
d) 3.000 3. int [] a = {1, 2, 3, 4, 5};
4. fun(a);
10. Which of the conversions are valid for the following C# code? 5. Console.ReadLine();
1. static void Main(string[] args) 6. }
2. { 7. static void fun(params int[] b )
3. int a = 22; 8. {
4. long b = 44; 9. int[] k = { 3, 4, 7, 8,'\0' };
5. double c = 1.406; 10. for (int i = 0; i < b.Length; i++)
6. b = a; 11. {
7. c = a; 12. b[i] = b[i] + k[i] ;
8. a = b; 13. Console.WriteLine( b[i] + " ");
9. b = c; 14. }
10. } 15. }
a) c = a, b = c a) Compile time error
b) a = c, b = a b) 3, 4, 7, 8, 5
c) b = a, c = a c) 3, 4, 7, 8, 5, 1, 2, 3, 4, 5
d) All of the mentioned d) 4, 6, 10, 12, 5
Arithmetic Operators
1. What will be the output of the following C# code? 6. What will be the output of the following C# code?
1. static void Main(string[] args) 1. static void Main(string[] args)
2. { 2. {
3. float a = 16.4f; 3. int [] a = {1, 2, 3, 4, 5};
4. int b = 12; 4. fun(a);
5. float c; 5. Console.ReadLine();
6. c = a * ( b + a) / (a - b) ; 6. }
7. Console.WriteLine("result is :" +c); 7. static void fun(params int[] b )
8. Console.ReadLine(); 8. {
9. } 9. for (int i = 0; i < b.Length; i++)
a) 106 10. {
b) 104.789 11. b[i] = b[i] * 5 ;
c) 105.8546 12. Console.WriteLine(b[i] + "");
d) 103.45 13. }
14. }
2. What will be the output of the following C# code? a) 1, 2, 3, 4, 5
advertisement b) 5, 10, 15, 20, 25
1. static void Main(string[] args) c) 5, 25, 125, 625, 3125
2. { d) 6, 12, 18, 24, 30
3. int a, b, c, x;
4. a = 90; 7. What will be the output of the following C# code?
5. b = 15; 1. static void Main(string[] args)
22
6. c = 3; 2. {
7. x = a - b / 3 + c * 2 - 1; 3. int[] a = { 2, 21, 34, 46, 85, 88, 90};
8. Console.WriteLine(x); 4. fun(a);
9. Console.ReadLine(); 5. Console.WriteLine(a + " ");
10. } 6. Console.ReadLine();
a) 92 7. }
b) 89 8. static void fun(params int [] b )
c) 90 9. {
d) 88 10. int [] c = { 1, 2, 3, 4, 5, 6, 7};
11. int i ;
3. What will be the output of the following C# code? 12. for (i = 0 ;i < b.Length ;i++)
1. static void Main(string[] args) 13. if (b[i] % 2 == 0)
2. { 14. {
3. int a, b, c, x; 15. c[i] = b[i];
4. a = 80; 16. }
5. b = 15; 17. Console.WriteLine("even numbers are:");
6. c = 2; 18. for (i = 0 ;i <= b.Length ;i++)
7. x = a - b / (3 * c) * ( a + c); 19. {
8. Console.WriteLine(x); 20. Console.WriteLine(c[i]);
9. Console.ReadLine(); 21. }
10. } 22. }
a) 78 a) Compile time error
b) -84 b) 2, 21, 34, 4, 6, 46, 88, 90
c) 80 c) 2, 4, 34, 46, 6, 88, 90
d) 98 d) 2, 34, 46, 88, 90

4. Correct order of priorities are: 8. Select the correct declaration of the defining array of parameters.
a) ‘/’ > ‘%’ > ‘*’ > ‘+’ a)
b) ‘/’ > ‘*’ > ‘%’ > ‘+’ void func(int[] x)
c) ‘*’ > ‘/’ > ‘%’ > ‘+’ {
d) ‘%’ > ‘*’ > ‘/’ > ‘+’
}
5. What will be the output of the following C# code? b)
1. int i, j = 1, k; void func(int x)
2. for (i = 0; i < 3; i++) { }
3. { c)
4. k = j++ - ++j; void func(param int[])
5. Console.Write(k + " "); {
6. }
a) -4 -3 -2 }
b) -6 -4 -1 d)
c) -2 -2 -2 void fun(param int[] x)
d) -4 -4 -4 {

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


23
1. static void Main(string[] args)
2. {
3. int b= 11;
4. int c = 7; 9. What will be the output of the following C# code?
5. int r = 5; 1. static void Main(string[] args)
6. int e = 2; 2. {
7. int l; 3. int[] x = { 80, 82, 65, 72, 83, 67 };
8. int v = 109; 4. fun(x);
9. int k; 5. Console.ReadLine();
10. int z,t,p; 6. }
11. z = b * c; 7. static void fun(params int [] b )
12. t = b * b; 8. {
13. p = b * r * 2; 9. int i;
14. l = (b * c) + (r * e) + 10; 10. for (i = 5; i >=0 ; i--)
15. k = v - 8; 11. {
16. Console.WriteLine(Convert.ToString(Convert.ToChar(z)) + 12. Console.WriteLine(Convert.ToChar(b[i]));
Convert.ToString(Convert.ToChar(t)) + " " + 13. }
Convert.ToString(Convert.ToChar(p)) + 14. }
Convert.ToString(Convert.ToChar(l)) + Convert.ToString(Convert.ToChar(v)) a) 67 83 72 65 82 80
+ Convert.ToString(Convert.ToChar(k))); b) P R A H S C
17. Console.ReadLine(); c) C S H A R P
18. } d) 80 82 65 72 83 67
a) My Name
b) My nAme 10. What will be the output of the following C# code?
c) My name 1. static void Main(string[] args)
d) Myname 2. {
3. int[] x = {65, 66, 67, 68, 69, 70};
7. What will be the output of the following C# code? 4. fun(x);
1. static void Main(string[] args) 5. Console.ReadLine();
2. { 6. }
3. int n = 5; 7. static void fun(params int[] b )
4. int x = 4; 8. {
5. int z, c, k; 9. int i;
6. for (c = 1; c <= n; c++) 10. for (i = 5; i > 0 ; i--)
7. { 11. {
8. for (k = 1; k <= c; k++) 12. b[i] = b[i] + 32;
9. { 13. Console.WriteLine(Convert.ToChar(b[i]));
10. z = 3 * x * x + 2 * x + 4 / x + 8; 14. }
11. Console.Write(Convert.ToString(Convert.ToChar(z))); 15. }
12. } a) A, B, C, D, E, F
13. Console.WriteLine("\n"); b) F, E, D, C, B, A
14. } c) f, e, d, c, b
15. Console.ReadLine(); d) b, c, d, e, f
16. } Object Oriented Concepts
a) Polymorphism
24
A 1. The capability of an object in Csharp to take number of different forms
AA and hence display behaviour as according is known as ___________
AAA a) Encapsulation
AAAA b) Polymorphism
b) c) Abstraction
A d) None of the mentioned
AB
ABC 2. What will be the output of the following C# code?
ABCD 1. public class sample
c) 2. {
A 3. public static int x = 100;
AA 4. public static int y = 150;
AAA 5.
AAAA 6. }
AAAAA 7. public class newspaper :sample
d) 8. {
A 9. new public static int x = 1000;
BC 10. static void Main(string[] args)
DEF 11. {
DEFG 12. console.writeline(sample.x + " " + sample.y + " " + x);
13. }
14. }
8. What will be the output of the following C# code? a) 100 150 1000
1. static void Main(string[] args) b) 1000 150 1000
2. { c) 100 150 1000
3. int n = 5; d) 100 150 100
4. int x = 4;
5. int z, c, k; 3. Which of the following keyword is used to change data and behavior of a
6. z = 3 * x * x + 2 * x + 4 / x + 8; base class by replacing a member of the base class with a new derived
7. for (c = 1; c <= n; c++) member?
8. { a) Overloads
9. for (k = 1; k <= c; k++) b) Overrides
10. { c) new
11. Console.Write(Convert.ToString(Convert.ToChar(z))); d) base
12. z++;
13. } Subscribe Now: C# Newsletter | Important Subjects Newsletters
14. Console.WriteLine("\n"); 4. Correct way to overload +operator?
15. } a) public sample operator + (sample a, sample b)
16. Console.ReadLine(); b) public abstract operator + (sample a,sample b)
17. } c) public static sample operator + (sample a, sample b)
a) d) all of the mentioned
A
AA 5. What will be the Correct statement of the following C# code?
AAA 1. public class maths
AAAA 2. {
25
AAAAA 3. public int x;
b) 4. public virtual void a()
A 5. {
AB 6.
ABC 7. }
ABCD 8.
ABCDE 9. }
c) 10. public class subject : maths
A 11. {
BC 12. new public void a()
DEF 13. {
GHIJ 14.
KLMNO 15. }
d) 16.
A 17. }
AB a) The subject class version of a() method gets called using sample class
BC reference which holds subject class object
BCD b) subject class hides a() method of base class
BCDE c) The code replaces the subject class version of a() with its math class
version
9. What will be the output of the following C# code? d) None of the mentioned
1. static void Main(string[] args)
2. { 6. Select the sequence of execution of function f1(), f2() & f3() in C# .NET
3. int a , b; CODE?
4. int c = 10; 1. class base
5. int d = 12; 2. {
6. int e = 5; 3. public void f1() {}
7. int f = 6; 4. public virtual void f2() {}
8. a = c * (d + e) / f + d; 5. public virtual void f3() {}
9. Console.WriteLine(a); 6. }
10. b = c * ( d + e / f + d); 7. class derived :base
11. Console.WriteLine(b); 8. {
12. if (a < b) 9. new public void f1() {}
13. { 10. public override void f2() {}
14. Console.WriteLine(" parentheses changes values"); 11. public new void f3() {}
15. } 12. }
16. else if (a > b) 13. class Program
17. { 14. {
18. Counterintelligence("they have same value"); 15. static void Main(string[] args)
19. } 16. {
20. Console.ReadLine(); 17. baseclass b = new derived();
21. } 18. b.f1 ();
a) They have same value 19. b.f2 ();
b) Parentheses changes values 20. b.f3 ();
c) Since both have equal values, no conclusion 21. }
26
d) None of the mentioned 22. }
a)
10. The correct way of incrementing the operators are: f1() of derived class get executed
a) ++ a ++ f2() of derived class get executed
b) b ++ 1 f3() of base class get executed
c) c += 1 b)
d) d =+ 1 f1() of base class get executed
Relational and Logical Operators f2() of derived class get executed
1. What will be the output of the following C# code? f3() of base class get executed
1. static void Main(string[] args) c)
2. { f1() of base class get executed
3. int a = 4; f2() of derived class get executed
4. int b = 5; f3() of derived class get executed
5. int c = 6; d)
6. int d = 8; f1() of derived class get executed
7. if (((a * b / c) + d) >= ((b * c + d ) / a)) f2() of base class get executed
8. { f3() of base class get executed
9. Console.WriteLine("Line 1 - a is greater to b");
10. Console.WriteLine((a * b / c) + d);
11. }
12. else 7. Which of the following statements is correct?
13. { a) Each derived class does not have its own version of a virtual method
14. Console.WriteLine("Line 1 - a is not greater to b"); b) If a derived class does not have its own version of virtual method then
15. Console.WriteLine((b * c + d )/ a); one in base class is used
16. } c) By default methods are virtual
17. } d) All of the mentioned
a)
"Line 1 - a is greater to b" 8. Correct code to be added for overloaded operator – for the following C#
11 code?
b) 1. class csharp
advertisement 2. {
"Line 1 - a is not greater to b" 3. int x, y, z;
9 4. public csharp()
c) Both are equal 5. {
d) None of the mentioned 6.
7. }
2. Check the following C# code whether the given relation operator works 8. public csharp(int a ,int b ,int c)
according to the if condition or not. 9. {
1. static void Main(string[] args) 10. x = a;
2. { 11. y = b;
3. int a = 10; 12. z = c;
4. int b = 5; 13. }
5. int c = 12; 14. Add correct set of code here
6. int e = 8; 15. public void display()
7. int d; 16. {
27
8. d = Convert.ToInt32((a * (c - b) / e + (b + c)) <= (e * (c + a) / (b + c) 17. console.writeline(x + " " + y + " " + z);
+ a)); 18. }
9. Console.WriteLine(d); 19. class program
10. if (d == 1) 20. {
11. { 21. static void Main(String[] args)
12. Console.WriteLine("C# is great language!"); 22. {
13. Console.WriteLine((a * (c - b) / e + (b + c))); 23. csharp s1 = new csharp(5 ,6 ,8);
14. } 24. csharp s3 = new csharp();
15. else 25. s3 = - s1;
16. { 26. s3.display();
17. Console.WriteLine("harsh is not great language!"); 27. }
18. Console.WriteLine((e * (c + a) / (b + c) + a)); 28. }
19. } 29. }
20. } a)
a) 1. public static csharp operator -(csharp s1)
0 2. {
C# is great! 3. csharp t = new csharp();
20 4. t.x = s1.x;
b) 5. t.y = s1.y;
0 6. t.z = -s1.z;
C# is not great! 7. return t;
25 8. }
c) b)
0 1. public static csharp operator -(csharp s1)
C# is great! 2. {
25 3. csharp t = new csharp();
d) 4. t.x = s1.x;
0 5. t.y = s1.y;
C# is not great! 6. t.z = s1.z;
20 7. return t;
8. }
c)
3. Which of the following is/are not Relational operators in C#.NET? 1. public static csharp operator -(csharp s1)
a) >= 2. {
b) <>= 3. csharp t = new csharp();
c) Not 4. t.x = -s1.x;
d) <= 5. t.y = -s1.y;
6. t.z = -s1.z;
4. What will be the output of the following C# code? 7. return t;
1. int n = 2; 8. }
2. int p = 4; d) None of the mentioned
3. int q = 5;
4. int w = 3; 9. Selecting appropriate method out of number of overloaded methods by
5. if ( !((p * q) /n <= (q * w) + n/p )) matching arguments in terms of number, type and order and binding that
6. { selected method to object at compile time is called?
28
7. Console.WriteLine( ++p + w++ + " " + ++n); a) Static binding
8. Console.WriteLine("b"); b) Static Linking
9. } c) Compile time polymorphism
10. else d) All of the mentioned
11. {
12. Console.WriteLine(--p + q-- + " " + --n); 10. Wrong statement about run time polymorphism is?
13. Console.WriteLine("a"); a) The overridden base method should be virtual, abstract or override
14. } b) An abstract method is implicitly a virtual method
a) c) An abstract inherited property cannot be overridden in a derived class
62 d) Both override method and virtual method must have same access level
b modifier
b)
81 Structures
a d1. What will be the correct statement in the following C# code?
c) 1. struct book
61 2. {
a 3. private String name;
d) 4. private int pages;
81 5. private Single price;
b 6. }
7. book b = new book();
a) New structure can be inherited from struct book
5. What will be the output of the following C# code? b) When the program terminates, variable b will get garbage collected
m = 5; c) The structure variable ‘b’ will be created on the stack
int y; d) When the program terminates, variable b will get garbage collected
1. y = m++;
2. y = ++m; advertisement
a) y = 5, m = 6 ; y = 5, m = 5 2. What will be the correct statement in the following C# code?
b) y = 6, m = 6; y = 7, m = 6 1. class trial
c) y = 5, m = 6; y = 7, m = 7 2. {
d) y = 5, m = 6; y = 7, m = 8 3. int i;
4. float d;
6. What will be the output of the following C# code? 5. }
1. static void Main(string[] args) 6. struct sample
2. { 7. {
3. int a = 3, b = 5, c = 1; 8. private int x;
4. int z = ++b; 9. private Single y;
5. int y = ++c; 10. private trial z;
6. b = Convert.ToInt32((Convert.ToBoolean(z)) && 11. }
(Convert.ToBoolean(y)) 12. sample s = new sample();
7. || Convert.ToBoolean(Convert.ToInt32(!(++a == b)))); a) trial object referred by z is created on the stack
8. a = Convert.ToInt32(Convert.ToBoolean(c) || b) z is created on the heap
Convert.ToBoolean(a--)); c) Both s and z will be created on the heap
9. Console.WriteLine(++a); d) s will be created on the stack
10. Console.WriteLine(++b);
29
11. Console.WriteLine(c); Subscribe Now: C# Newsletter | Important Subjects Newsletters
12. } 3. Choose the correct statement among the following which supports the
a) 2, 2, 1 fact that C# does not allow the creation of empty structures?
b) 2, 3, 2 a) C#.NET supports creation of abstract user-defined data types using
c) 2, 2, 2 structures
d) 2, 0, 9 b) By having empty structures, it would mean that the new data types have
no data associated with, which does not make any sense in C#.NET
7. What will be the output of the following C# code? c) Basic reason to create structures is the inability to represent real life
1. static void Main(string[] args) objects using standard data types offered by the language
2. { d) All of the mentioned
3. int a = 4, b = 5, c = 7, u = 9;
4. int h; 4. Choose the correct statement about structures as to why they are defined
5. h = (Convert.ToInt32(u < b)) + (a + b--) + 2; as value types but not reference types?
6. Console.WriteLine(h); a) Since space required for structure variables is allocated on stack which is
7. Console.WriteLine(b); a form of memory that is automatically available when a variable to be used
8. Console.WriteLine(u < b); is in scope
9. } b) Structures generally are used to represent user defined data types that
a) 12, 5, 0 consists of small amount of data in them. Hence using stack for declaration
b) 11, 4, False of such variables is not a problem
c) 11, 5, 0 c) All of the mentioned
d) 12, 4, False d) None of the mentioned

8. What will be the output of the following C# code? 5. Choose the wrong statement about structures in C#.NET?
1. static void Main(string[] args) a) Structures can be declared within a procedure
2. { b) Structures can implement an interface but they cannot inherit from
3. int m = 10, n = 5, p = 20; another structure
4. bool b1 = m * p / n <= p * n / m ; c) Structure members cannot be declared as protected
5. int l = p - 2 * m; d) A structure cannot be empty
6. bool b2 = l == 0;
7. int z = Convert.ToInt32(b2); 6. The correct way to define a variable of type struct abc in the following C#
8. int k = Convert.ToInt32(b1); code?
9. Console.WriteLine(k); 1. struct abc
10. Console.WriteLine(z); 2. {
11. } 3. public string name;
a) 0 0 4. protected internal int age;
b) 1 0 5. private Single sal;
c) 0 1 6. }
d) 1 1 a) abc e = new abc();
b) abc();
9. What will be the output of the following C# code? c)
1. class method1 abc e;
2. { e = new abc;
3. public int fun(int m) d) abc e = new abc;
4. {
5. return( m++ % 10); 7. Which of the following is the correct way to settle down values into the
30
6. } structure variable ‘e’ defined in the following C# code snippet?
7. } 1. struct emp
8. class Program 2. {
9. { 3. public String name;
10. static void Main(string[] args) 4. public int age;
11. { 5. public Single sal;
12. int a = 23, b = 0, c; 6. }
13. method1 z = new method1(); 7. emp e = new emp();
14. c = z.fun (++b * --a % 2); a)
15. int d = (z.fun (c-- + --a)); 1. e.name = "Ankit";
16. Console.WriteLine(c); 2. e.age = 24;
17. Console.WriteLine(a++); 3. e.sal = 200;
18. Console.WriteLine(d); b)
19. Console.ReadLine(); 1. With emp e
20. } 2. {
21. } 3. .name = "Ankit";
a) -1, 22, 0 4. .age = 24;
b) -1, 21, 1 5. .sal = 200;
c) 0, 22, 1 6. }
d) 0, 22, 0 c)
1. name = "Ankit";
10. What will be the output of the following C# code? 2. age = 24;
1. static void Main(string[] args) 3. sal = 200;
2. { d) All of the mentioned
3. int a = 8, b = 6, c = 10;
4. int d = a * c * 2 / Convert.ToInt32(Math.Pow ((c - b), 2)); 8. When does a structure variable get destroyed?
5. if (d == (c = Convert.ToInt32(Math.Sqrt (a * a + b * b))) && c == a) When no reference refers to it, it will get garbage collected
10) b) Depends on whether it is created using new or without new operator
6. { c) As variable goes out of the scope
7. Console.WriteLine("figure is hypotenuse"); d) Depends on either we free its memory using free() or delete()
8. }
9. else 9. Calculate the number of bytes a structure variable s occupies in the
10. { memory if it is defined as follows.
11. Console.WriteLine("figure is square"); 1. class abc
12. } 2. {
13. } 3. int i;
a) Figure is square 4. Decimal d;
b) Figure is hypotenuse 5. }
c) False 6. struct sample
d) None of the mentioned 7. {
Bitwise and Conditional Operators 8. private int x;
1. What will be the output of the following C# code? 9. private Single y;
1. static void Main(string[] args) 10. private trial z;
2. { 11. }
3. byte varA = 10; 12. sample s = new sample();
31
4. byte varB = 20; a) 24 bytes
5. long result = varA & varB; b) 8 bytes
6. Console.WriteLine("{0} AND {1} Result :{2}", varA, varB, result); c) 16 bytes
7. varA = 10; d) 12 bytes
8. varB = 10;
9. result = varA & varB; 10. What will be the output of the following C# code?
10. Console.WriteLine("{0} AND {1} Result : {2}", varA, varB, result); 1. {
11. Console.ReadLine(); 2. struct abc
12. } 3. {
a) 0, 20 4. public int i;
b) 10, 10 5. }
c) 0, 10 6. class Program
d) 0, 0 7. {
8. static void Main(string[] args)
2. What will be the output of the following C# code? 9. {
1. public static void Main() 10. sample a = new sample();
2. { 11. a.i = 10;
3. byte varA = 10; 12. fun(ref a);
4. byte varB = 20; 13. Console.WriteLine(a.i);
5. long result = varA | varB; 14. }
6. Console.WriteLine("{0} OR {1} Result :{2}", varA, varB, result); 15. public static voidn fun(ref sample x)
7. varA = 10; 16. {
8. varB = 10; 17. x.i = 20;
9. result = varA | varB; 18. Console.WriteLine(x.i);
10. Console.WriteLine("{0} OR {1} Result : {2}", varA, varB, result); 19. }
11. } 20. }
a) 20, 10 21. }
b) 30, 10 a)
c) 10, 20 10
d) 10, 10 10
b)
3. What will be the output of the following C# code? 20
1. static void Main(string[] args) 10
2. { c)
3. byte b1 = 0 * AB; 10
4. byte b2 = 0 * 99; 20
5. byte temp; d)
6. temp = (byte) ~b2; 20
7. Console.Write( temp + " "); 20
8. temp = (byte) (b1 << b2);
9. Console.Write(temp + " "); 11. Select the wrong statements among the following?
10. temp = (byte)(b2 >> 2); a) A structure can contain properties
11. Console.WriteLine(temp); b) A structure can contain constructors
12. Console.ReadLine(); c) A structure can contain protected data members
13. } d) A structure can contain constants
32
a) 101 0 34
b) 103 2 38 12. Which of the following is the correct result for the given statement in the
c) 102 0 38 C#.NET statement given below?
d) 101 1 35 p=q
1. struct employee
4. Which of the following options is not a Bitwise Operator in C#? 2. {
a) &, | 3. private int employee id;
b) ^, ~ 4. private string city;
c) <<, >> 5. }
d) +=, -= 6. employee q = new employee();
7. employee p;
5. What will be the output of the following C# code? 8. p = q;
1. bool a = true; a) Elements of ‘q’ will be copied into corresponding elements of p
2. bool b = false; b) Address stored in q will get copied into p
3. a |= b; c) Address of first element of q will get copied into p
4. Console.WriteLine(a); d) Once assignment is over. q will go out of scope and hence get exited
5. Console.ReadLine(); forever
a) 0
b) 1 13. What will be the output of the following C# code?
c) True 1. {
d) False 2. struct abc
3. {
6. Select the relevant C# code set to fill up the blank for the following C# 4. int i;
program? 5. }
1. static void Main(string[] args) 6. class Program
2. { 7. {
3. int x = 10, y = 20; 8. static void Main(string[] args)
4. int res; 9. {
5. /*_______________*/ 10. abc x = new abc();
6. Console.WriteLine(res); 11. abc z;
7. } 12. x.i = 10;
a) x % y == 0 ? (x == y ? (x += 2):(y = x + y)):y = y*10; 13. z = x;
b) x % y == 0 ? y += 10:(x += 10); 14. z.i = 15;
c) x % y == 0 ? return(x) : return (y); 15. console.Writeline(x.i + " " + y.i)
d) All of the mentioned 16. }
17. }
7. What will be the output of the following C# code? 18. }
1. static void Main(string[] args) a) 10 10
2. { b) 10 15
3. int y = 5; c) 15 10
4. int x; d) 15 15
5. int k = (!(Convert.ToInt32(y) > 10))? x = y + 3 : x = y + 10; Enumerations
6. Console.WriteLine(x); 1. Choose the correct statements about enum used in C#.NET?
7. Console.WriteLine(y); a) An enum variable cannot have a private access modifier
8. Console.ReadLine(); b) An enum variable can be defined inside a class or a namespace
33
9. } c) An enum variable cannot have a protected access modifier
a) 5, 8 d) An enum variable cannot have a public access modifier
b) 10, 4
c) 8, 5 2. Which among the following cannot be used as a datatype for an enum in
d) 11, 8 C#.NET?
a) short
8. Which among the following is a conditional operator? b) double
a) ‘:?’ c) int
b) ?; d) all of the mentioned
c) ?:
d) ?? 3. What will be the output of the following C# code?
advertisement
9. What will be the output of the following C# code? 1. enum days:int
1. public static void Main(string[] args) 2. {
2. { 3. sunday = -3,
3. int a = 4; 4. monday,
4. int c = 2; 5. tuesday
5. bool b = (a % c == 0 ? true : false); 6. }
6. Console.WriteLine(b.ToString()); 7. Console.WriteLine((int)days.sunday);
7. if (a/c == 2) 8. Console.WriteLine((int)days.monday);
8. { 9. Console.WriteLine((int)days.tuesday);
9. Console.WriteLine("true"); a) -3 0 1
10. } b) 0 1 2
11. else c) -3 -2 -1
12. { d) sunday monday tuesday
13. Console.WriteLine("false");
14. } Note: Join free Sanfoundry classes at Telegram or Youtube
15. Console.ReadLine(); 4. What will be the correct statement of the following C# code?
16. } 1. enum color:byte
a) 2. {
True 3. yellow = 500,
False 4. green = 1000,
b) 5. pink = 1300
False 6. }
True a) byte value cannot be assigned to enum elements
c) b) enum elements should always take successive values
True c) enum must always be of int type
True d) When the valid range of byte exceeds, the compiler will report an error
d)
False 5. Wrong statement about enum used in C#.NET is?
False a) An enum can be declared inside a class
b) An object cannot be assigned to an enum variable
c) An enum can be declared outside a class
10. Arrange the operators in the increasing order as defined in C#. d) An enum can have Single and Double values
!=, ?:, &, ++, &&
34
a) ?: < && < != < & < ++ 6. What will be the output of the following C# code?
b) ?: < && < != < ++ < & 1. enum per
c) ?: < && < & <!= < ++ 2. {
d) ?: < && < != < & < ++ 3. a,
Looping Statements 4. b,
IF Statements1. What will be the output of the following C# code? 5. c,
1. static void Main(string[] args) 6. d,
2. { 7. }
3. int i = 30; 8. per.a = 10;
4. int j = 25 % 25; 9. Console.writeline(per.b);
5. if (Convert.ToBoolean(Convert.ToInt32(i = j))) a) 11
6. { b) 1
7. Console.WriteLine("In if"); c) 2
8. } d) compile time error
9. else
10. { 7. What will be the output of the following C# code?
11. Console.WriteLine("In else"); 1. enum color:int
12. } 2. {
13. Console.WriteLine("In main"); 3. red,
14. Console.ReadLine(); 4. green,
15. } 5. blue = 5,
a) In if 6. cyan,
b) In else 7. pink = 10,
c) 8. brown
In if 9. }
In main 10. console.writeline((int)color.green);
advertisement 11. console.writeline((int)color.brown);
d) a) 2 10
In else b) 2 11
In main c) 1 11
d) 1 5
2. What will be the output of the following C# code?
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. 8. What will be the output of the following C# code?
Participate Now! 1. enum letters
1. static void Main(string[] args) 2. {
2. { 3. a,
3. int i; 4. b,
4. int b = 8, a = 32; 5. c
5. for (i = 0; i <= 10; i++) 6. }
6. { 7. letters l;
7. if ((a / b * 2)== 2) 8. l = letters.a;
8. { 9. Console.writeline(l);
9. Console.WriteLine( i + " "); a) -1
10. continue; b) 0
11. } c) a
35
12. else if (i != 4) d) letters.a
13. Console.Write(i + " ");
14. else 9. What will be the output of the following C# code?
15. break; 1. enum colors
16. } 2. {
17. Console.ReadLine(); 3. red,
18. } 4. black,
a) 1 2 3 4 5 6 7 8 9 5. pink
b) 0 1 2 3 4 5 6 7 8 6. }
c) 0 1 2 3 7. colors s = colors.black;
d) 0 1 2 3 4 8. type t;
9. t = c.GetType();
3. Which of the following conditions are true in the following C# code? 10. string[] str;
1. static void Main(string[] args) 11. str = Enum.GetNames(t);
2. { 12. Console.WriteLine(str[0]);
3. Console.WriteLine("Enter a letter:"); a) 0
4. char c = (char)Console.Read(); b) black
5. if (Char.IsDigit(c) == true) c) red
6. Console.WriteLine("A number"); d) 1
7. else if (char.IsLower(c) == true)
8. Console.WriteLine("A lowercase letter"); 10. Choose the correct statement about enum used in C#.NET?
9. else if (char.IsUpper(c) == true) a) By default the first enumerator has a value equal to the number of
10. Console.WriteLine("An uppercase letter"); elements present in the list
11. Console.ReadLine(); b) Values of the enum elements cannot be populated from database
12. } c) The value of each successive enumerator is decreased by 1
13. a. Enter a letter : d) An enumerator has a white space in its name
14. a
15. An uppercase letter 11. Which among the following differentiates enum in C#.NET from enum in
16. b. Enter a letter : C language?
17. A a) C is strictly a typed language, C#.NET also is a strictly typed language
18. An uppercase letter b) In C, language variables of enum types can be used interchangeably with
19. c. Enter a letter : integers using type casts while enum variables cannot be used as a normal
20. 2 integers in C#.NET
21. A number c) None of the mentioned
22. d. Enter a letter : d) All of the mentioned
23. 2 Fundamentals of Inheritance
24. A lowercase letter. . Which procedure among the following should be used to implement a ‘Has
a) a, b, c a’ or a ‘Kind of’ relationship between two entities?
b) b, c, d a) Polymorphism
c) a, d, b b) Inheritance
d) b, c c) Templates
d) All of the mentioned
4. What will be the output of the following C# code?
1. static void Main(string[] args) 2. The number of levels of inheritance are?
2. { a) 5
36
3. int i, j; b) 4
4. for (i = 2; i >= 0; i--) c) 3
5. { d) 2
6. for (j = 0; j <= 2; j++)
7. { 3. What does the following C# code signify?
8. if (i == j) advertisement
9. { 1. class a
10. Console.WriteLine("1"); 2. {
11. } 3.
12. else 4.
13. { 5.
14. Console.WriteLine("0"); 6. }
15. } 7. class b : a
16. } 8. {
17. Console.WriteLine("\n"); 9. variable declaration;
18. Console.ReadLine(); 10. method declaration;
19. } 11. }
20. } a) Declaration of a base class
a) b) Declaration of a subclass
100 c) Declaration of base class & subclass and how subclass inherits the base
010 class
001 d) None of the mentioned
b)
010 Sanfoundry Certification Contest of the Month is Live. 100+ Subjects.
100 Participate Now!
001 4. In an inheritance chain through which of the following, the base class and
c) its components are accessible to the derived class?
001 a) Scope resolution operator(:)
010 b) Class visibility modifiers (public,private etc.)
100 c) Dot operator (.)
d) d) All of the mentioned
100
001 5. Select the class visibility modifiers among the following:
010 a) Private, protected, public, internal
b) Private, protected, public, internal, protected internal
5. Select the correct ‘if statement’ to be filled in the following C# code? c) Private, protected, public
1. static void Main(string[] args) d) All of the mentioned
2. {
3. int []num = {50, 65, 56, 88, 43, 52}; 6. In Inheritance concept, which of the following members of base class are
4. int even = 0, odd = 0; accessible to derived class members?
5. for (int i = 0 ;i < num.Length ;i++) a) static
6. { b) protected
7. /*___________________________*/ c) private
8. } d) shared
9. Console.WriteLine("Even Numbers:" +even);
37
10. Console.WriteLine("Odd Numbers:" +odd); 7. Wrong statement about inheritance in C# .NET?
11. Console.ReadLine(); a) In inheritance chain, object construction begins from base class towards
12. } derived class
a) b) Inheritance cannot extend base class functionality
1. if ((num % 2) == 0) c) A derived class object contains all base class data
2. { d) All of the mentioned
3. even += 1;
4. } 8. A class member declared protected becomes member of subclass of
5. else which type?
6. { a) public member
7. odd += 1; b) private member
8. } c) protected member
b) d) static member
1. if((num * i) == 0)
2. { 9. Which of the following functionality is facilitated by inheritance
3. even += 1; mechanism?
4. } a) Use the existing functionality of base class
5. else b) Override the existing functionality of base class
6. { c) Implements new functionality in derived class
7. odd += 1; d) All of the mentioned
8. }
c) 10. Which statements among following are correct?
1. if(num[i] % 2 == 0) a) We can derive a class from a base class even if source code of base
2. { class not available
3. even += 1; b) Multiple inheritance is different from multiple levels of inheritance
4. } c) It is legal to make objects of one class as members of another class
5. else d) All of the mentioned
6. {
7. odd += 1; 11. If base class consist of two private integers, one static integer and
8. } derived class consist of two static integers and one private integer. What
d) would be the size of derived class object?
1. if(num[i] % 2 = 0) a) size of object depends on sizes of its non static data members
2. { b) size of a derived class object is sum of sizes of non static data members
3. even += 1; of base class and derived class
4. } c) size of object is calculated using sizeof() method
5. else d) none of the mentioned
6. {
7. odd += 1; 12. Which is the correct way to create an object of the given class abc?
8. } a) Declaring existing class as sealed
b) Declaring existing class as override
c) Declaring existing class as overloads
6. What will be the output of the following C# code? d) Declaring existing class as shadows
1. static void Main(string[] args)
2. { 13. Given class sample is inherited by class sample 1. Which are the correct
3. int a = 15, b = 10, c = 1; statements about construction of object of class sample?
38
4. if (Convert.ToBoolean(a) && (b > c)) a) While creating the object firstly the constructor of class sample will be
5. { called followed by constructor of class sample 1
6. Console.WriteLine("cquestionbank"); b) The constructor of only sample class will be called
7. } c) While creating the object firstly constructor of class sample 1 will be
8. else called followed by constructor of class sample
9. { d) The order of calling constructors depend on whether constructors in class
10. break; sample and sample 1 are private or public
11. }
12. } 14. Which form of inheritance is not supported directly by C# .NET?
a) cquestionbank a) Multiple inheritance
b) It will print nothing b) Multilevel inheritance
c) Compile time error c) Single inheritance
d) Run time error d) Hierarchical inheritance

7. What will be the output of the following C# code? 15. If no access modifier for a class is specified, then class accessibility is
1. static void Main(string[] args) defined as?
2. { a) public
3. int a = 5; b) protected
4. if (Convert.ToBoolean((.002f) -(0.1f))) c) private
5. Console.WriteLine("Sachin Tendulkar"); d) internal
6. else if (a == 5) Inheritance Implementation
7. Console.WriteLine("Rahul Dravid"); 1. What will be the output of the following C# code?
8. else 1. class sample
9. Console.WriteLine("Ms Dhoni"); 2. {
10. Console.ReadLine(); 3. public int i;
11. } 4. void display()
a) Rahul Dravid 5. {
b) Sachin Tendulkar 6. Console.WriteLine(i);
c) Ms Dhoni 7. }
d) Warning : Unreachable Code 8. }
9. class sample1 : sample
8. What will be the output of the following C# code? 10. {
1. static void Main(string[] args) 11. public int j;
2. { 12. public void display()
3. int a = -1; 13. {
4. int b = -1; 14. Console.WriteLine(j);
5. if (Convert.ToBoolean (++a = ++b)) 15. }
6. Console.WriteLine("a"); 16. }
7. else 17. class Program
8. Console.WriteLine("b"); 18. {
9. Console.ReadLine(); 19. static void Main(string[] args)
10. } 20. {
a) a 21. sample1 obj = new sample1();
b) b 22. obj.i = 1;
c) Compile time error 23. obj.j = 2;
39
d) Code execute successfully with no output 24. obj.display();
25. Console.ReadLine();
9. What will be the output of the following C# code? 26. }
1. static void Main(string[] args) 27. }
2. { a) 1
3. int a = 5, b = 10; b) 3
4. if (Convert.ToBoolean(Convert.ToInt32(0xB))) c) 2
5. if (Convert.ToBoolean(Convert.ToInt32(022))) d) Compile Time error
6. if (Convert.ToBoolean(Convert.ToInt32('\xeb')))
7. Console.WriteLine("java"); advertisement
8. else ; 2. What will be the Correct statement in the following C# code?
9. else ; 1. class sample
10. else ; 2. {
11. } 3. protected int index;
a) Compile time error: Misplaced else 4. public sample()
b) Compile time error: Undefined symbol 5. {
c) java 6. index = 0;
d) Warning: Condition is always true 7. }
8. }
10. What will be the output of the following C# code? 9. class sample 1: sample
1. static void Main(string[] args) 10. {
2. { 11. public void add()
3. int a = 5, b = 10; 12. {
4. if (Convert.ToBoolean(Convert.ToInt32(++a)) || 13. index += 1;
Convert.ToBoolean(Convert.ToInt32(++b))) 14. }
5. { 15. }
6. Console.WriteLine(a + "\n" + b); 16. class Program
7. } 17. {
8. else 18. static void Main(string[] args)
9. Console.WriteLine(" C# "); 19. {
10. } 20. sample 1 z = new sample 1();
a) 6 11 21. z . add();
b) 6 16 22. }
c) 6 12 23. }
d) 6 10 a) Index should be declared as protected if it is to become available in
Switch Statement inheritance chain
1. What will be the output of the following C# code? b) Constructor of sample class does not get inherited in sample 1 class
1. static void Main(string[] args) c) During constructing an object referred to by z, Firstly constructor of
2. { sample class will be called followed by constructor of sample 1 class
3. int movie = 1; d) All of the mentioned
4. switch (movie << 2 + movie)
5. { Note: Join free Sanfoundry classes at Telegram or Youtube
6. default: 3. The following C# code is run on single level of inheritance. What will be
7. Console.WriteLine("3 Idiots"); the Correct statement in the following C# code?
8. break; 1. class sample
40
9. case 4: 2. {
10. Console.WriteLine("Ghazini"); 3. int i = 10;
11. break; 4. int j = 20;
12. case 5: 5. public void display()
13. Console.WriteLine("Krishh"); 6. {
14. break; 7. Console.WriteLine("base method ");
15. case 8: 8. }
16. Console.WriteLine("Race"); 9. }
17. break; 10. class sample1 : sample
18. } 11. {
19. Console.ReadLine(); 12. public int s = 30;
20. } 13. }
a) 3 Idiots 14. class Program
b) Ghazini 15. {
c) Race 16. static void Main(string[] args)
d) Krishh 17. {
18. sample1 obj = new sample1();
2. What will be the output of the following C# code? 19. Console.WriteLine("{0}, {1}, {2}", obj.i, obj.j, obj.s);
Note: Join free Sanfoundry classes at Telegram or Youtube 20. obj.display();
1. static void Main(string[] args) 21. Console.ReadLine();
2. { 22. }
3. int i = 2, j = 4; 23. }
4. switch (i + j * 2) a)
5. { 10, 20, 30
6. case 1 : base method
7. case 2 : b) 10, 20, 0
8. Console.WriteLine("1 and 2"); c) compile time error
9. break; d) base method
10. case 3 to 10:
11. Console.WriteLine("3 to 10"); 4. What will be size of the object created depicted by C# code snippet?
12. break; 1. class baseclass
13. } 2. {
14. Console.ReadLine(); 3. private int a;
15. } 4. protected int b;
a) 3 to 10 will be printed 5. public int c;
b) 1 and 2 will be printed 6. }
c) The code reports an error as missing ; before : 7. class derived : baseclass
d) The code gives output as 3 to 10 8. {
9. private int x;
3. What will be the output of the following C# code? 10. protected int y;
1. static void Main(string[] args) 11. public int z;
2. { 12. }
3. int i = 2, k = 3; 13. class Program
4. switch (i - k) 14. {
5. { 15. static Void Main(string[] args)
41
6. case -1: 16. {
7. ++i; 17. derived a = new derived();
8. ++k; 18. }
9. break; 19. }
10. case 2: a) 20 bytes
11. --i; b) 12 bytes
12. ++k; c) 16 bytes
13. break; d) 24 bytes
14. default:
15. i += 3; 5. What will be the output of the following C# code?
16. k += i; 1. class sample
17. break; 2. {
18. } 3. public sample()
19. Console.WriteLine(i + "\n" + k); 4. {
20. Console.ReadLine(); 5. Console.WriteLine("THIS IS BASE CLASS constructor");
21. } 6. }
a) 2 3 3 7. }
b) 3 2 3 8. public class sample1 : sample
c) 3 4 4 9. {
d) 5 10 10 10.
11. }
4. What will be the output of the following C# code? 12. class Program
1. static void Main(string[] args) 13. {
2. { 14. static void Main(string[] args)
3. int const p = 0; 15. {
4. switch (3 * 5 / 6) 16. sample1 obj = new sample1();
5. { 17. Console.ReadLine();
6. case p: 18. }
7. Console.WriteLine("A"); 19. }
8. break; a) Code executes successfully prints nothing
9. case p * 1: b) This is base class constructor
10. Console.WriteLine("B"); c) Compile time error
11. break; d) None of the mentioned
12. case p - 2:
13. Console.WriteLine("C"); 6. Select the statement which should be added to the current C# code to get
14. break; the output as 10 20?
15. default: 1. class baseclass
16. Console.WriteLine("D"); 2. {
17. } 3. protected int a = 20;
18. } 4. }
a) A 5. class derived : baseclass
b) B 6. {
c) C 7. int a = 10;
d) Compile time error 8. public void math()
9. {
42
5. What will be the output of the following C# code? 10. /* add code here */
1. static void Main(string[] args) 11. }
2. { 12. }
3. int i = 2, j = 3, k = 4; a) Console.writeline( a + ” ” + this.a);
4. switch (i + j - k) b) Console.Writeline( mybase.a + ” ” + a);
5. { c) console.writeline(a + ” ” + base.a);
6. case 0: case 2: case 4: d) console.writeline(base.a + ” ” + a);
7. ++i;
8. k += j; 7. What will be the Correct statement in the following C# code?
9. break; 1. class baseclass
10. case 1: case 3: case 5 : 2. {
11. --i; 3. int a;
12. k -= j; 4. public baseclass(int a1)
13. break; 5. {
14. default: 6. a = a1;
15. i += j; 7. console.writeline(" a ");
16. break; 8. }
17. } 9. class derivedclass : baseclass
18. Console.WriteLine(i + "\n" + j + "\n" + k); 10. {
19. Console.ReadLine(); 11. public derivedclass (int a1) : base(a1)
20. } 12. {
a) 1 3 1 13. console.writeline(" b ");
b) 2 3 4 14. }
c) 5 3 4 15. }
d) Compile time error 16. class program
17. {
6. What will be the output of the following C# code? 18. static void main(string[] args)
1. static void Main(string[] args) 19. {
2. { 20. derivedclass d = new derivedclass(20);
3. int i = 9 , j = 7; 21. }
4. switch (i - j + 3) 22. }
5. { 23. }
6. case 9: 7: a) Compile time error
7. j += 6; b)
8. break; b
9. case 5: a
10. i -= 4; c)
11. break; a
12. } b
13. Console.WriteLine(i + "\n" + j); d) The program will work correctly if we replace base(a1) with
14. Console.ReadLine(); base.baseclass(a1)
15. }
a) 5 7 8. Which C# statement should be added in function a() of class y to get
b) 9 13 output “i love csharp”?
c) Compile time error 1. class x
43
d) 9 7 2. {
3. public void a()
7. What will be the output of the following C# code? 4. {
1. static void Main(string[] args) 5. console.write("bye");
2. { 6. }
3. switch (5) 7. }
4. { 8. class y : x
5. case 5.0f: 9. {
6. Console.WriteLine("harsh"); 10. public void a()
7. break; 11. {
8. case 5: 12. /* add statement here */
9. Console.WriteLine("amish"); 13. console.writeline(" i love csharp ");
10. break; 14. }
11. case 5.0L: 15. }
12. Console.WriteLine("ANKIT"); 16. class program
13. break; 17. {
14. default: 18. static void main(string[] args)
15. Console.WriteLine("ashish"); 19. {
16. } 20. y obj = new obj();
17. Console.ReadLine(); 21. obj.a();
18. } 22. }
a) amish 23. }
b) ANKIT a) x.a();
c) harsh b) a();
d) Compile time error c) base.a();
d) x::a();
8. What will be the output of the following C# code?
1. static void Main(string[] args) 9. Which statements are correct?
2. { a) If a base class consists of a member function fun() and a derived class do
3. int i; not have any function with this name. An object of derived class can access
4. int j = 1; fun()
5. int []ar = {21, 22, 13, 4}; b) A class D can be derived from class C, which is derived from class B
6. switch (ar[j]) which in turn is derived from class A
7. { c) If a base class and a derived class each include a member function with
8. case 1: same name, the member function of the derived class will be called by
9. i++; object of derived class
10. break; d) All of the mentioned
11. case 2:
12. i += 2; 10. What will be the output of the following C# code?
13. j = 3; 1. class A
14. continue; 2. {
15. case 3: 3. public int i;
16. i %= 2; 4. protected int j;
17. j = 4; 5. }
18. continue; 6. class B : A
44
19. default: 7. {
20. --i; 8. public int j;
21. } 9. public void display()
22. Console.WriteLine(i); 10. {
23. Console.ReadLine(); 11. base.j = 3;
24. } 12. Console.WriteLine(i + " " + j);
a) 23 13. }
b) 15 14. }
c) Compile time error 15. class Program
d) 12 16. {
17. static void Main(string[] args)
9. What will be the output of the following C# code? 18. {
1. static void Main(string[] args) 19. B obj = new B();
2. { 20. obj.i = 1;
3. char ch = Convert.ToChar('a' | 'b' | 'c'); 21. obj.j = 2;
4. switch (ch) 22. obj.display();
5. { 23. Console.ReadLine();
6. case 'A': 24. }
7. case 'a': 25. }
8. Console.WriteLine("case A|case a"); a) 2 1
9. break; b) 1 0
10. case 'B': c) 0 2
11. case 'b': d) 1 2
12. Console.WriteLine("case B|case b");
13. break; 11. What will be the output of the following C# code?
14. case 'C': 1. class A
15. case 'c': 2. {
16. case 'D': 3. public int i;
17. case 'd': 4. private int j;
18. Console.WriteLine("case D|case d"); 5. }
19. break; 6. class B :A
20. } 7. {
21. Console.ReadLine(); 8. void display()
22. } 9. {
a) Compile time error 10. base.j = base.i + 1;
b) case A|case a 11. Console.WriteLine(base.i + " " + base.j);
c) case B|case b 12. }
d) case D|case d 13. }
14. class Program
10. What will be the output of the following C# code? 15. {
1. static void Main(string[] args) 16. static void Main(string[] args)
2. { 17. {
3. char ch = 'p'; 18. B obj = new B();
4. switch (ch) 19. obj.i = 1;
5. { 20. obj.j = 2;
45
6. case 'p': 21. obj.display();
7. Console.WriteLine("coco" + "\t" + Convert.ToInt32(ch)); 22. Console.ReadLine();
8. break; 23. }
9. default: 24. }
10. Console.WriteLine("default"); a) 1, 3
11. break; b) 2, 3
12. } c) 1, 2
13. Console.WriteLine("main"); d) compile time error
14. }
a) coco main 12. Which of these keywords is used to refer to member of base class from
b) coco 112 a sub class?
c) coco 112 main a) upper
d) compile time error b) base
For Loop Statements c) this
1. What will be the output of the following C# code? d) none of the mentioned
1. static void Main(string[] args)
2. { 13. Which of these operators must be used to inherit a class?
3. int i; a) :
4. for (i = 0; ; ) b) &
5. { c) ::
6. Console.WriteLine("hello"); d) extends
7. }
8. Console.ReadLine(); 14. What will be the output of the following C# code?
9. } 1. using System;
a) No output 2. public class BaseClass
b) hello 3. {
c) hello printed infinite times 4. public BaseClass()
d) Code will give error as expression syntax 5. {
6. Console.WriteLine("I am a base class");
2. What will be the output of the following C# code? 7. }
Subscribe Now: C# Newsletter | Important Subjects Newsletters 8. }
1. static void Main(string[] args) 9. public class ChildClass : BaseClass
2. { 10. {
3. float f; 11. public ChildClass()
4. for (f = 0.1f; f <= 0.5; f += 1) 12. {
5. Console.WriteLine( ++f ); 13. Console.WriteLine ("I am a child class");
6. Console.ReadLine(); 14. }
7. } 15. static void Main()
a) 1.1 16. {
b) 0.1 17. ChildClass CC = new ChildClass();
c) 0.1 0.2 0.3 0.4 0.5 18. }
d) None of the mentioned 19. }
a)
3. What will be the output of the following C# code? I am a base class
1. static void Main(string[] args) I am a child class
46
2. { b)
3. int I, X; I am a child class
4. for (I = 1; I <= (9 % 2 + I); I++) I am a base class
5. { c) Compile time error
6. X = (I * 3 + I * 2) / I; d) None of the mentioned
7. Console.WriteLine(X); Method Overloading
8. } 1. The process of defining two or more methods within the same class that
9. Console.ReadLine(); have same name but different parameters list?
10. } a) Method overloading
a) Output of code is 5 10 b) Method overriding
b) Output is 5 5 5 5 c) Encapsulation
c) Print 5 infinite times d) None of the mentioned
d) None of the mentioned
2. Which of these can be overloaded?
4. What will be the output of the following C# code? a) Constructors
1. static void Main(string[] args) b) Methods
2. { c) Both Constructors & Methods
3. int I, J = 0; d) None of the mentioned
4. for (I = 1; I < 10; ) ;
5. { 3. What will be the output of the following C# code?
6. J = J + I; 1. class Program
7. I += 2; 2. {
8. } 3. static void Main(string[] args)
9. Console.WriteLine("Sum of first 10 even numbers is:"+J); 4. {
10. Console.ReadLine(); 5. Console.WriteLine( vol(10));
11. } 6. Console.WriteLine( vol(2.5f, 5));
a) 1 2 3 4 5 6 7 8 9 7. Console.WriteLine( vol( 5l, 4, 5));
b) 25 8. Console.ReadLine();
c) 1 9. }
d) Run time error 10. static int vol(int x)
11. {
5. What will be the output of the following C# code? 12. return(x * x * x);
1. static void Main(string[] args) 13. }
2. { 14. static float vol(float r, int h)
3. int i = 5; 15. {
4. for (; Convert.ToBoolean(Convert.ToInt32(i)); 16. return(3.14f * r * r * h);
Console.WriteLine(i--)) ; 17. }
5. Console.ReadLine(); 18. static long vol(long l, int b, int h)
6. } 19. {
a) 4 3 2 1 20. return(l * b * h);
b) 3 2 1 21. }
c) 5 4 3 2 1 22. }
d) 2 1 a)
1000
6. What will be the output of the following C# code? 0
47
1. static void Main(string[] args) 100
2. { b)
3. int i, s = 0; advertisement
4. for (i = 1; i <= 10; s = s + i, i++); 0
5. { 0
6. Console.WriteLine(s); 100
7. } c) compile time error
8. Console.ReadLine(); d)
9. } 1000
a) Code report error 98.125
b) Code runs in infinite loop condition 100
c) Code gives output as 0 1 3 6 10 15 21 28 36 45
d) Code give output as 55
4. What will be the output of the following C# code?
7. Which statement is correct among the mentioned statements? 1. class overload
i. The for loop works faster than a while loop 2. {
ii. for( ; ; )implements an infinite loop 3. public int x;
a) Only i is correct 4. int y;
b) Only ii is correct 5. public int add(int a)
c) Both i and ii are correct 6. {
d) Both i and ii are incorrect 7. x = a + 1;
8. return x;
8. What will be the output of the following C# code? 9. }
1. { 10. public int add(int a, int b)
2. int i; 11. {
3. Console.WriteLine("Hi"); 12. x = a + 2;
4. for (i = 1; i <= 10; i++) 13. return x;
5. Program.Main(args); 14. }
6. Console.ReadLine(); 15. }
7. } 16. class Program
a) Prints ‘Hi’ for one time 17. {
b) Prints ‘Hi’ for infinite times 18. static void Main(string[] args)
c) Stack overflow exception Condition generated 19. {
d) None of the mentioned 20. overload obj = new overload();
21. overload obj1 = new overload();
9. Which of the C# code should be added to get the following output? 22. int a = 0;
1. ***** 23. obj.add(6);
2. **** 24. obj1.add(6, 2);
3. *** 25. Console.WriteLine(obj.x);
4. ** 26. Console.WriteLine(obj1.x);
5. * 27. Console.ReadLine();
6. static void Main(string[] args) 28. }
7. { 29. }
8. int i,j; a)
9. /* Add code here */ 8
48
10. 8
11. } b)
a) 0
for (i = 0;i &lt;= 4; i++) 2
{ c)
for(j = 0;j &lt;= 4; j++) 8
console.WriteLine("*"); 10
console.WriteLine("\n"); d)
} 7
b) 8
for (i = 0;i &lt;= 4; i++)
{
for(j = 4;j &lt;= i; j--) 5. What will be the output of the following C# code?
console.WriteLine("*"); 1. static void Main(string[] args)
console.WriteLine("\n"); 2. {
} 3. int i = 5;
c) 4. int j = 6;
for (i = 0;i &lt;= 4; i++) 5. add(ref i);
{ 6. add(6);
for (j = i;j &lt;= 4; j++) 7. Console.WriteLine(i);
console.WriteLine("*"); 8. Console.ReadLine();
console.WriteLine("\n"); 9. }
} 10. static void add(ref int x)
d) 11. {
for ( i = 0;i &lt;= 4; i++) 12. x = x * x;
{ 13. }
for (j = 0;j &lt;= i; j++) 14. static void add(int x)
console.WriteLine("*"); 15. {
console.WriteLine("\n"); 16. Console.WriteLine(x * x * x);
} 17. }
a) Compile time error
b)
25
10. What will be the output of the following C# code? 0
1. static void Main(string[] args) c)
2. { 216
3. int i; 0
4. for (i =-3; i <= 3; i++) d)
5. { 216
6. switch (i) 25
7. {
8. case 0:
9. Console.WriteLine("zero"); 6. What will be the output of the following C# code?
10. break; 1. class maths
11. } 2. {
49
12. if (i > 0) 3. public int x;
13. Console.WriteLine("A"); 4. public double y;
14. else if (i < 0) 5. public int add(int a, int b)
15. Console.WriteLine("B"); 6. {
16. } 7. x = a + b;
17. Console.ReadLine(); 8. return x;
18. } 9. }
a) B B zero A A A 10. public int add(double c, double d)
b) B zero A A A 11. {
c) B B B zero A A A 12. y = c + d;
d) A A A zero B B B 13. return (int)y;
14. }
11. Which of the following is not infinite loop? 15. public maths()
a) for( ;’0′; ) 16. {
b) for( ;’0′; ) 17. this.x = 0;
c) for( ;’1′; ) 18. this.y = 0;
d) for( ;’1′; ) 19. }
20. }
12. What will be the output of the following C# code? 21. class Program
1. static void Main(string[] args) 22. {
2. { 23. static void Main(string[] args)
3. int i, j; 24. {
4. for (i = 1, j = i; i <= 3 && j >= 0; i++, j--) 25. maths obj = new maths();
5. { 26. int a = 4;
6. if (i == j) 27. double b = 3.5;
7. continue; 28. obj.add(a, a);
8. else 29. obj.add(b, b);
9. Console.WriteLine(j); 30. Console.WriteLine(obj.x + " " + obj.y);
10. } 31. Console.ReadLine();
11. Console.ReadLine(); 32. }
12. } 33. }
a) i = 0, j = 1; a) 4, 3.5
b) i = 1, j = 0; b) 8, 0
c) j = 0; c) 7.5, 8
d) None of the mentioned d) 8, 7

13. What will be the output of the following C# code? 7. What will be the output of the following C# code?
1. static void Main(string[] args) 1. class maths
2. { 2. {
3. int i = -10; 3. public static void fun1()
4. for ( ;Convert.ToBoolean(Convert.ToInt32(i)) ;Console.WriteLine(i+ 4. {
+)) ; 5. Console.WriteLine("method 1 :");
5. Console.ReadLine(); 6. }
6. } 7. public void fun2()
a) -9 -8 -7 -6 -5 -4 -3 -2 -1 8. {
50
b) -10 -9 -8 -7 -6 -5 -4 -3 -2 9. fun1();
c) -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 10. Console.WriteLine("method 2 :");
d) -8 -7 -6 -5 -4 -3 -2 -1 11. }
While Loop Statements 12. public void fun2(int k)
1. What will be the output of the following C# code? 13. {
1. static void Main(string[] args) 14. Console.WriteLine(k);
2. { 15. fun2();
3. int i, j; 16. }
4. for (i = 1; i <= 3; i++) 17. }
5. { 18. class Program
6. j = 1; 19. {
7. while (i % j == 2) 20. static void Main(string[] args)
8. { 21. {
9. j++; 22. maths obj = new maths();
10. } 23. maths.fun1();
11. Console.WriteLine(i + " " + j); 24. obj.fun2(20);
12. } 25. Console.ReadLine();
13. Console.ReadLine(); 26. }
14. } 27. }
a) 11 21 31 a)
b) 1 12 13 1 method 1:
c) 11 21 31 method 2:
d) 1 1 2 1 3 1 20
method 1:
2. What will be the output of the following C# code? b)
advertisement method 2:
1. static void Main(string[] args) 20
2. { method 1:
3. float s = 0.1f; method 1:
4. while (s <= 0.5f) c)
5. { method 1:
6. ++s; 0
7. Console.WriteLine(s); method 2:
8. } method 2:
9. Console.ReadLine(); d)
10. } method 1:
a) 0.1 20
b) 1.1 method 1:
c) 0.1 0.2 0.3 0.4 0.5 method 2:
d) No output
8. What is the process of defining a method in terms of itself, that is a
3. What will be the output of the following C# code? method that calls itself?
1. static void Main(string[] args) a) Polymorphism
2. { b) Abstraction
3. int i; c) Encapsulation
51
4. i = 0; d) Recursion
5. while (i++ < 5)
6. { 9. What will be the output of the following C# code?
7. Console.WriteLine(i); 1. class maths
8. } 2. {
9. Console.WriteLine("\n"); 3. public int fun1(int k)
10. i = 0; 4. {
11. while ( ++i < 5) 5. k = 20;
12. { 6. return k;
13. Console.WriteLine(i); 7. }
14. } 8. public Single fun1(float t)
15. Console.ReadLine(); 9. {
16. } 10. t = 3.4f;
a) 11. return t;
1234 12. }
12345 13. }
b) 14. class Program
123 15. {
1234 16. static void Main(string[] args)
c) 17. {
12345 18. maths obj = new maths();
1234 19. int i;
d) 20. i = obj.fun1(30);
12345 21. Console.WriteLine(i);
12345 22. Single j;
23. j = obj.fun1(2.5f);
24. Console.WriteLine(j);
4. What will be the output of the following C# code? 25. Console.ReadLine();
1. static void Main(string[] args) 26. }
2. { 27. }
3. int x = 0; a)
4. while (x < 20) 30
5. { 2.5f
6. while (x < 10) b)
7. { 2.5f
8. if (x % 2 == 0) 30
9. { c)
10. Console.WriteLine(x); 20
11. } 2.5f
12. x++; d)
13. } 20
14. } 3.4f
15. Console.ReadLine();
16. }
a) 10. What will be the output of the following C# code?
52
1 2 3 4 5 6 7 8 9 10 1. class maths
11 12 13 14 15 16 17 18 19 20 2. {
b) 0 2 4 6 8 10 12 14 16 18 20 3. public int fun(int k, int y)
c) 0 2 4 6 8 4. {
d) 0 2 4 6 8 10 5. return k + y;
6. }
5. What will be the output of the following C# code? 7. public int fun1(int t, float z)
1. static void Main(string[] args) 8. {
2. { 9. return (t+(int)z);
3. int x; 10. }
4. x = Convert.ToInt32(Console.ReadLine()); 11. }
5. int c = 1; 12. class Program
6. while (c <= x) 13. {
7. { 14. static void Main(string[] args)
8. if (c % 2 == 0) 15. {
9. { 16. maths obj = new maths();
10. Console.WriteLine("Execute While " + c + "\t" + "time"); 17. int i;
11. } 18. int b = 90;
12. c++; 19. int c = 100;
13. } 20. int d = 12;
14. Console.ReadLine(); 21. float l = 14.78f;
15. } 22. i = obj.fun(b, c);
16. for x = 8. 23. Console.WriteLine(i);
a) 24. int j = (obj.fun1(d, l));
Execute while 1 time 25. Console.WriteLine(j);
Execute while 3 time 26. Console.ReadLine();
Execute while 5 time 27. }
Execute while 7 time 28. }
b) a) 190, 26.78f
Execute while 2 time b) 0, 26.78f
Execute while 4 time c) 190, 26
Execute while 6 time d) 190, 0
Execute while 8 time
c) 11. What will be the output of the following C# code?
Execute while 1 time 1. class maths
Execute while 2 time 2. {
Execute while 3 time 3. public int fun(int k, int y, int n)
Execute while 4 time 4. {
Execute while 5 time 5. Console.WriteLine(k + " " + y + " " + n);
Execute while 6 time 6. return (k);
Execute while 7 time 7. }
d) 8. public int fun1(int t,float z)
Execute while 2 time 9. {
Execute while 3 time 10. Console.WriteLine(t + " " + z);
Execute while 4 time 11. return t;
53
Execute while 5 time 12. }
13. }
6. What will be the output of the following C# code? 14. class Program
1. static void Main(string[] args) 15. {
2. { 16. static void Main(string[] args)
3. int n, r; 17. {
4. n = Convert.ToInt32(Console.ReadLine()); 18. maths obj = new maths();
5. while (n > 0) 19. int b = 90;
6. { 20. int c = 100;
7. r = n % 10; 21. int d ;
8. n = n / 10; 22. float l;
9. Console.WriteLine(+r); 23. int i = obj.fun(b, c, 12);
10. } 24. int j = (obj.fun1(12, 14.78f));
11. Console.ReadLine(); 25. Console.ReadLine();
12. } 26. }
13. for n = 5432. 27. }
a) 3245 a)
b) 2354 0, 0, 0
c) 2345 12, 14.78
d) 5423 b)
0, 0, 0
7. Correct syntax for while statement is: 0, 0
a) c)
1. while 90, 100, 12
2. { 12, 14
3. d)
4. 90, 100, 12
5. 12, 14.78
6. }(condition);
b) 12. What will be the output of the following C# code?
1. while(condition) 1. class maths
2. { 2. {
3. 3. public int fun(int ii)
4. 4. {
5. }; 5. return(ii > 0 ? ii :ii * -1);
c) 6. }
1. while(condition) 7. public long fun(long ll)
2. { 8. {
3. 9. return(ll > 0 ? ll :ll * -1);
4. 10. }
5. } 11. public double fun( double dd)
d) 12. {
1. while(condition); 13. return(dd > 0 ? dd :dd * -1);
2. { 14. }
3. 15. }
54
4. 16. class Program
5. } 17. {
18. static void Main(string[] args)
19. {
8. What will be the output of the following C# code? 20. maths obj = new maths();
1. static void Main(string[] args) 21. int i = -25;
2. { 22. int j ;
3. float i = 1.0f, j = 0.05f; 23. long l = -100000l ;
4. while (i < 2.0f && j <= 2.0f) 24. long m;
5. { 25. double d = -12.34;
6. Console.WriteLine(i++ - ++j); 26. double e;
7. } 27. j = obj.fun(i);
8. Console.ReadLine(); 28. m = obj.fun(l);
9. } 29. e = obj.fun(d);
a) 0.05f 30. Console.WriteLine(j + " " + m + " " + e);
b) 1.50f 31. Console.ReadLine();
c) -0.04999995f 32. }
d) 1.50f 33. }
a) 1 1 1
9. What will be the output of the following C# code? b) 0 0 0
1. static void Main(string[] args) c) 25 100000 12.34
2. { d) -25 -100000 -12.34
3. int i = 0; Method Overriding
4. while (i <= 50) 1. Which keyword is used to declare a base class method while performing
5. { overriding of base class methods?
6. if (i % 10 == 0) a) this
7. continue; b) virtual
8. else c) override
9. break; d) extend
10. i += 10;
11. Console.WriteLine(i % 10); 2. The process of defining a method in a subclass having same name &
12. } type signature as a method in its superclass is known as?
13. } a) Method overloading
a) code prints output as 0 0 0 0 0 b) Method overriding
b) code prints output as 10 20 30 40 50 c) Method hiding
c) infinite loop but doesn’t print anything d) None of the mentioned
d) Code generate error
3. Which of the given modifiers can be used to prevent Method overriding?
10. What will be the output of the following C# code? a) Static
1. static void Main(string[] args) b) Constant
2. { c) Sealed
3. int i = 1, j = 1; d) final
4. while (++i <= 10)
5. { advertisement
6. j++; 4. Select the correct statement from the following?
55
7. } a) Static methods can be a virtual method
8. Console.WriteLine(i+ " " +j); b) Abstract methods can be a virtual method
9. Console.ReadLine(); c) When overriding a method, the names and type signatures of the override
10. } method must be the same as the virtual method that is being overridden
a) 12 11 d) We can override virtual as well as nonvirtual methods
b) 10 11
c) 11 10 5. Which of the following cannot be used to declare a class as a virtual?
d) 11 12 a) Methods
b) Properties
11. What will be the output of the following C# code? c) Events
1. static void Main(string[] args) d) Fields
2. {
3. int i = 1; Note: Join free Sanfoundry classes at Telegram or Youtube
4. while (i <= 1) 6. What will be the output of the following C# code?
5. { 1. class A
6. if ('A' < 'a') 2. {
7. { 3. public int i;
8. Console.WriteLine("Hello..."); 4. public void display()
9. } 5. {
10. else 6. Console.WriteLine(i);
11. { 7. }
12. Console.WriteLine("Hi..."); 8. }
13. } 9. class B: A
14. i++; 10. {
15. } 11. public int j;
16. Console.ReadLine(); 12. public void display()
17. } 13. {
a) Hi… 14. Console.WriteLine(j);
b) Hello…. 15. }
c) Hi…infinite times 16. }
d) Hello infinite times 17. class Program
18. {
12. What will be the output of the following C# code? 19. static void Main(string[] args)
1. static void Main(string[] args) 20. {
2. { 21. B obj = new B();
3. int i = 0; 22. obj.i = 1;
4. while (i++ != 0) ; 23. obj.j = 2;
5. Console.WriteLine(i); 24. obj.display();
6. Console.ReadLine(); 25. Console.ReadLine();
7. } 26. }
a) -127 to +127 27. }
b) 0 to 127 a) 0
c) 1 b) 2
d) Infinite loop condition c) 1
Do While Loop Statements d) Compile time error
56
1. What will be the output of the following C# code?
1. static void Main(string[] args) 7. What will be the output of the following C# code?
2. { 1. class A
3. int i = 1, j = 2, k = 3; 2. {
4. do 3. public virtual void display()
5. { 4. {
6. Console.WriteLine((Convert.ToBoolean(Convert.ToInt32(i++))) 5. Console.WriteLine("A");
7. && (Convert.ToBoolean(Convert.ToInt32(++j)))); 6. }
8. }while (i <= 3); 7. }
9. Console.ReadLine(); 8. class B: A
10. } 9. {
a) 0 0 0 10. public override void display()
b) True True True 11. {
c) 1 1 1 12. Console.WriteLine(" B ");
d) False False False 13. }
14. }
2. What will be the output of the following C# code? 15. class Program
advertisement 16. {
1. static void Main(string[] args) 17. static void Main(string[] args)
2. { 18. {
3. float i = 1.0f, j = 0.05f; 19. A obj1 = new A();
4. do 20. B obj2 = new B();
5. { 21. A r;
6. Console.WriteLine(i++ - ++j); 22. r = obj1;
7. }while (i < 2.0f && j <= 2.0f); 23. r.display();
8. Console.ReadLine(); 24. r = obj2;
9. } 25. r.display();
a) 0.05 26. Console.ReadLine();
b) -0.05 27. }
c) 0.95 28. }
d) -0.04999995 a) A, A
b) B, B
3. What will be the output of the following C# code? c) Compile time error
1. static void Main(string[] args) d) A, B
2. {
3. int i = 1, j = 5; 8. The modifier used to hide the base class methods is?
4. do a) Virtual
5. { b) New
6. Console.WriteLine(i = i++ * j); c) Override
7. }while (i <= 10); d) Sealed
8. Console.ReadLine();
9. } 9. To override a method in the subclass, the base class method should be
a) 5 10 15 20 25 30 35 40 45 50 defined as?
b) 5 25 a) Virtual
c) 5 11 16 21 26 31 36 41 46 51 b) Abstract
57
d) 5 30 c) Override
d) All of the mentioned
4. For the incomplete C# program below, which of the C# code fragment will
not result in an infinite loop? 10. What will be the output of the following C# code?
1. static void Main(string[] args) 1. class a
2. { 2. {
3. int i = 1234 ,j = 0; 3. public void fun()
4. /*ADD CODE HERE */ 4. {
5. Console.WriteLine(j); 5. Console.WriteLine("base method");
6. } 6. }
a) 7. }
do 8. class b: a
{ 9. {
j = j + (i % 10); 10. public new void fun()
}while ((i = i / 10)!= 0); 11. {
b) 12. Console.WriteLine(" derived method ");
do 13. }
{ 14. }
j = j + (i % 10); 15. class Program
}while ((i / 10)!= 0); 16. {
c) 17. static void Main(string[] args)
do 18. {
{ 19. b k = new b();
j = j + (i % 10); 20. k.fun();
}while ((i % 10)!= 0); 21. Console.ReadLine();
d) 22. }
do 23. }
{ a) Base method
j = j + (i % 10); b) Derived method
}while ((i/10 == 0)!= 0); c) Code runs successfully prints nothing
d) Compile time error
Constructor Overloading
5. What will be the output of the following C# code? 1. What will be the output of the following C# code?
1. static void Main(string[] args) 1. class maths
2. { 2. {
3. long x; 3. public int length;
4. x = Convert.ToInt32(Console.ReadLine()); 4. public int breadth;
5. do 5. public maths(int x, int y)
6. { 6. {
7. Console.WriteLine(x % 10); 7. length = x;
8. }while ((x = x / 10) != 0); 8. breadth = y;
9. Console.ReadLine(); 9. Console.WriteLine(x + y);
10. } 10. }
11. enter x = 1234. 11. public maths(double x, int y)
a) number of digits present in x 12. {
58
b) prints ‘1’ 13. length = (int)x;
c) prints reverse of x 14. breadth = y;
d) prints sum of digits of ‘x’ 15. Console.WriteLine(x * y);
16. }
6. What will be the output of the following C# code? 17. }
1. static void Main(string[] args) 18. class Program
2. { 19. {
3. int i, s = 0, a = 1, d; 20. static void Main(string[] args)
4. i = Convert.ToInt32(Console.ReadLine()); 21. {
5. do 22. maths m = new maths(20, 40);
6. { 23. maths k = new maths(12.0, 12);
7. d = i % (2 * 4); 24. Console.ReadLine();
8. s = s + d * a; 25. }
9. }while ((Convert.ToInt32(i = i / (2 * 4))) != 0 26. }
10. && (Convert.ToBoolean(Convert.ToInt32((a) = (a * 10))))); a) 60, 24
11. Console.WriteLine(s); b) 60, 0
12. Console.ReadLine(); c) 60, 144
13. } d) 60, 144.0
14. enter i = 342.
a) It finds binary equivalent of i 2. What will be the output of the following C# code?
b) It finds octal equivalent of i Sanfoundry Certification Contest of the Month is Live. 100+ Subjects.
c) It finds sum of digits of i Participate Now!
d) It finds reverse of i 1. class maths
2. {
7. What is the correct syntax for do while loop? 3. public int length;
a) 4. public int breadth;
do; 5. public maths(int x)
{ 6. {
statement; 7. length = x + 1;
}while (condition); 8. }
b) 9. public maths(int x, int y)
do(condition) 10. {
{ 11. length = x + 2;
statement; 12. }
}while; 13. }
c) 14. class Program
do 15. {
{ 16. static void Main(string[] args)
statement; 17. {
}while (condition) 18. maths m = new maths(6);
d) 19. maths k = new maths(6, 2);
do 20. Console.WriteLine(m.length);
{ 21. Console.WriteLine(k.length);
statement; 22. Console.ReadLine();
}while (condition); 23. }
59
24. }
a) 8, 8
8. What will be the output of the following C# code? b) 0, 2
1. static void Main(string[] args) c) 8, 10
2. { d) 7, 8
3. int x = 10;
4. do 3. What will be the output of the following C# code?
5. { 1. class maths
6. Console.WriteLine( x++); 2. {
7. } 3. public maths()
8. while(Convert.ToBoolean(5) && Convert.ToBoolean(4) && 4. {
Convert.ToBoolean(3) 5. Console.WriteLine("constructor 1 :");
9. && Convert.ToBoolean(2) && Convert.ToBoolean(1) && 6. }
Convert.ToBoolean(0)); 7. public maths(int x)
10. Console.ReadLine(); 8. {
11. } 9. int p = 2;
a) 13 10. int u;
b) 15 11. u = p + x;
c) 11 12. Console.WriteLine("constructor 2: " +u);
d) 10 13. }
14. }
9. What will be the output of the following C# code? 15. class Program
1. static void Main(string[] args) 16. {
2. { 17. static void Main(string[] args)
3. int x; 18. {
4. for (x = 10; x <= 15; x++) 19. maths k = new maths(4);
5. while (Convert.ToBoolean(Convert.ToInt32(x))) 20. maths t = new maths();
6. { 21. Console.ReadLine();
7. do 22. }
8. { 23. }
9. Console.WriteLine(1); a)
10. if (Convert.ToBoolean(x >> 1)) constructor 1:
11. continue; constructor 2: 6
12. }while (Convert.ToBoolean(0)); b)
13. break; constructor 2: 6
14. } constructor 2: 6
15. Console.ReadLine(); c)
16. } constructor 2: 6
a) 0 0 0….infinite times constructor 1:
b) 1 1 1….infinite times d) none of the mentioned
c) 1 1 1 1 1 1
d) System outofflow exception error 4. What will be the output of the following C# code?
1. class maths
10. What will be the output of the following C# code? 2. {
1. static void Main(string[] args) 3. int i;
60
2. { 4. public maths(int x)
3. int x = 0; 5. {
4. do 6. i = x;
5. { 7. Console.WriteLine(" hello: ");
6. x++; 8. }
7. if (x == 5) 9. }
8. { 10. class maths1 : maths
9. x++; 11. {
10. continue; 12. public maths1(int x) :base(x)
11. break; 13. {
12. } 14. Console.WriteLine("bye");
13. Console.WriteLine(x + " "); 15. }
14. } 16. }
15. }while (x < 10); 17. class Program
a) 1 2 3 4 5 18. {
b) 10 19. static void Main(string[] args)
c) 5 6 7 8 9 10 20. {
d) 1 2 3 4 5 6 7 8 9 10 21. maths1 k = new maths1(12);
22. Console.ReadLine();
11. What will be the output of the following C# code? 23. }
1. static void Main(string[] args) 24. }
2. { a) hello bye
3. int x; b) 12 hello
4. for (x = 1; x <= 3; x++) c) bye 12
5. { d) Compile time error
6. int j = 1;
7. do 5. What will be the output of the following C# code?
8. { 1. class maths
9. j++; 2. {
10. }while (x % j == 2); 3. int i;
11. Console.WriteLine(x + " " + j); 4. public maths(int ii)
12. } 5. {
13. Console.ReadLine(); 6. ii = 12;
14. } 7. int j = 12;
a) 1 12 1 3 1 8. int r = ii * j;
b) 1 12 13 1 9. Console.WriteLine(r);
c) 12 22 32 10. }
d) 11 21 31 11. }
Continue, Goto Statements 12. class maths1 : maths
1. What will be the output of the following C# code? 13. {
1. static void Main(string[] args) 14. public maths1(int u) :base(u)
2. { 15. {
3. int i; 16. u = 13;
4. Console.WriteLine("enter value of i:"); 17. int h = 13;
5. i = Convert.ToInt32(Console.ReadLine()); 18. Console.WriteLine(u + h);
61
6. if (i < 7) 19. }
7. { 20. }
8. i++; 21. class maths2 : maths1
9. continue; 22. {
10. } 23. public maths2(int k) :base(k)
11. Console.WriteLine("final value of i:" +i); 24. {
12. Console.ReadLine(); 25. k = 24;
13. } 26. int o = 6 ;
a) 12 27. Console.WriteLine(k /o);
b) 11 28. }
c) Compile time error 29. }
d) 13 30. class Program
31. {
advertisement 32. static void Main(string[] args)
2. What will be the output of the following C# code? 33. {
1. static void Main(string[] args) 34. maths2 t = new maths2(10);
2. { 35. Console.ReadLine();
3. int i; 36. }
4. Console.WriteLine("enter value of i:"); 37. }
5. i = Convert.ToInt32(Console.ReadLine()); a) 4, 26, 144
6. if ( i % 2 == 0) b) 26, 4, 144
7. goto even: c) 144, 26, 4
8. else d) 0, 0, 0
9. {
10. Console.WriteLine("number is odd:"); 6. Which keyword is used to refer baseclass constructor to subclass
11. Console.ReadLine(); constructor?
12. } a) This
13. even: b) Static
14. Console.WriteLine("number is even:"); c) Base
15. Console.ReadLine(); d) Extend
16. }
17. for i = 4. 7. When we call a constructor method among different given constructors.
a) number is odd We match the suitable constructor by matching the name of constructor first,
b) number is even then the number and then the type of parameters to decide which
c) Compile time error constructor is to be overloaded. The process is also known as?
d) none of the mentioned a) Method overriding
b) Inheritance
Note: Join free Sanfoundry classes at Telegram or Youtube c) Polymorphism
3. What will be the output of the following C# code? d) Encapsulation
1. static void Main(string[] args)
2. { 8. Correct statement about constructor overloading in C# is?
3. int i = 1, j; a) Overloaded constructors have the same name as the class
4. do b) Overloaded constructors cannot use optional arguments
5. { c) Overloaded constructors can have different type of number of arguments
6. for (j = 1; ; j++) as well as differ in number of arguments
62
7. { d) All of the mentioned
8. if (j > 2)
9. break; 9. What will be the output of the following C# code?
10. if (i == j) 1. class maths
11. continue; 2. {
12. Console.WriteLine(i + " " + j); 3. static maths()
13. } 4. {
14. i++; 5. int s = 8;
15. } while (i < 3); 6. Console.WriteLine(s);
16. Console.ReadLine(); 7. }
17. } 8. public maths(int f)
a) 9. {
12 10. int h = 10;
21 11. Console.WriteLine(h);
b) 12. }
21 13. }
12 14. class Program
c) 15. {
13 16. static void Main(string[] args)
21 17. {
d) 18. maths p = new maths(0);
11 19. Console.ReadLine();
21 20. }
21. }
a) 10, 10
b) 0, 10
4. What will be the output of the following C# code? c) 8, 10
1. static void Main(string[] args) d) 8, 8
2. {
3. int i = 10 , j = 0; 10. What will be the output of the following C# code?
4. label: 1. class maths
5. i--; 2. {
6. if ( i > 0) 3. int i;
7. { 4. public maths(int ii)
8. Console.WriteLine(i+ " "); 5. {
9. goto label; 6. ii = -25;
10. } 7. int g;
11. Console.ReadLine(); 8. g = ii > 0 ? ii : ii * -1;
12. } 9. Console.WriteLine(g);
a) 1 2 3 4 5 6 7 8 9 10 10. }
b) 10 9 8 7 6 5 4 3 2 1 0 11. }
c) 9 8 7 6 5 4 3 2 1 12. class maths1 :maths
d) 10 9 8 7 6 5 4 3 2 1 13. {
14. public maths1(int ll) :base(ll)
5. What will be the output of the following C# code? 15. {
63
1. static void Main(string[] args) 16. ll = -1000;
2. { 17. Console.WriteLine((ll > 0 ? ll : ll * -1));
3. int i = 0, j = 0; 18. }
4. while (i < 2) 19. }
5. { 20. class Program
6. l1: i--; 21. {
7. while (j < 2) 22. static void Main(string[] args)
8. { 23. {
9. Console.WriteLine("hi\n"); 24. maths1 p = new maths1(6);
10. goto l1; 25. Console.ReadLine();
11. } 26. }
12. } 27. }
13. Console.ReadLine(); a)
14. } -25
a) hi hi hi -1000
b) hi hi b)
c) hi -1000
d) hi hi hi…..infinite times -25
c)
6. What will be the output of the following C# code? 25
1. static void Main(string[] args) 1000
2. { d) None of the mentioned
3. int i = 0; Abstract Class & Methods
4. if (i == 0) 1. A type of class which does not have its own objects but acts as a base
5. { class for its subclass is known as?
6. goto label; a) Static class
7. } b) Sealed class
8. label: Console.WriteLine("HI..."); c) Abstract class
9. Console.ReadLine(); d) None of the mentioned
10. }
a) Hi…infinite times 2. The modifier used to define a class which does not have objects of its
b) Code runs prints nothing own but acts as a base class for its subclass is?
c) Hi Hi a) Sealed
d) Hi… b) Static
c) New
7. What will be the output of the following C# code? d) Abstract
1. static void Main(string[] args)
2. { 3. Choose the correct statements among the following:
3. int i = 0, j = 0; a) An abstract method does not have implementation
4. l1: while (i < 2) b) An abstract method can take either static or virtual modifiers
5. { c) An abstract method can be declared only in abstract class
6. i++; d) All of the mentioned
7. while (j < 3)
8. { advertisement
9. Console.WriteLine("loop\n"); 4. What will be the output of the following C# code?
64
10. goto l1; 1. namespace ConsoleApplication4
11. } 2. {
12. } 3. abstract class A
13. Console.ReadLine(); 4. {
14. } 5. int i;
a) loop is printed infinite times 6. public abstract void display();
b) loop 7. }
c) loop loop 8. class B: A
d) Compile time error 9. {
10. public int j;
8. What will be the output of the following C# code? 11. public override void display()
1. static void Main(string[] args) 12. {
2. { 13. Console.WriteLine(j);
3. int i= 0,k; 14. }
4. label: Console.WriteLine(i); 15. }
5. if (i == 0) 16. class Program
6. goto label; 17. {
7. Console.ReadLine(); 18. static void Main(string[] args)
8. } 19. {
a) 0 0 0 0 20. B obj = new B();
b) 0 0 0 21. obj.j = 2;
c) 0 infinite times 22. obj.display();
d) 0 23. Console.ReadLine();
24. }
9. What will be the output of the following C# code? 25. }
1. static void Main(string[] args) 26. }
2. { a) 0
3. int i = 0; b) 2
4. int j = 0; c) Compile time error
5. for (i = 0; i < 4; i++) d) 1
6. {
7. for (j = 0; j < 3; j++) Sanfoundry Certification Contest of the Month is Live. 100+ Subjects.
8. { Participate Now!
9. if (i > 1) 5. What will be the output of the following C# code?
10. continue; 1. namespace ConsoleApplication4
11. Console.WriteLine("Hi \n"); 2. {
12. } 3. abstract class A
13. } 4. {
14. Console.ReadLine(); 5. public int i ;
15. } 6. public int j ;
a) Prints hi 4 times 7. public abstract void display();
b) Prints hi 3 times 8. }
c) Prints hi 6 times 9. class B: A
d) Prints hi infinite times 10. {
11. public int j = 5;
65
10. Select the output for the following set of code : 12. public override void display()
1. static void Main(string[] args) 13. {
2. { 14. this.j = 3;
3. int a = 0; 15. Console.WriteLine(i + " " + j);
4. int i = 0; 16. }
5. int b; 17. }
6. for (i = 0; i < 5; i++) 18. class Program
7. { 19. {
8. a++; 20. static void Main(string[] args)
9. Console.WriteLine("Hello \n"); 21. {
10. continue; 22. B obj = new B();
11. } 23. obj.i = 1;
12. Console.ReadLine(); 24. obj.display();
13. } 25. Console.ReadLine();
a) print hello 4 times 26. }
b) print hello 3 times 27. }
c) print hello 5 times 28. }
d) print hello infinite times a) 1, 5
b) 0, 5
11. What will be the output of the following C# code? c) 1, 0
1. static void Main(string[] args) d) 1, 3
2. {
3. Console.WriteLine("HI"); 6. What will be the output of the following C# code?
4. continue; 1. namespace ConsoleApplication4
5. Console.WriteLine("Hello"); 2. {
6. Console.ReadLine(); 3. abstract class A
7. } 4. {
a) Hi Hello 5. public int i;
b) Hi 6. public abstract void display();
c) Hello 7. }
d) Compile time error 8. class B: A
3. Classes 9. {
Fundamentals of Class1. What will be the output of the following C# code? 10. public int j;
1. class sample 11. public int sum;
2. { 12. public override void display()
3. public int i; 13. {
4. public int[] arr = new int[10]; 14. sum = i + j;
5. public void fun(int i, int val) 15. Console.WriteLine(+i + "\n" + +j);
6. { 16. Console.WriteLine("sum is:" +sum);
7. arr[i] = val; 17. }
8. } 18. }
9. } 19. class Program
10. class Program 20. {
11. { 21. static void Main(string[] args)
12. static void Main(string[] args) 22. {
66
13. { 23. A obj = new B();
14. sample s = new sample(); 24. obj.i = 2;
15. s.i = 10; 25. B obj1 = new B();
16. sample.fun(1, 5); 26. obj1.j = 10;
17. s.fun(1, 5); 27. obj.display();
18. Console.ReadLine(); 28. Console.ReadLine();
19. } 29. }
20. } 30. }
a) sample.fun(1, 5) will not work correctly 31. }
b) s.i = 10 cannot work as i is ‘public’ a)
c) sample.fun(1, 5) will set value as 5 in arr[1] 2, 10
d) s.fun(1, 5) will work correctly 12
b)
2. Which of the following is used to define the member of a class externally? 0, 10
a) : 10
b) :: c)
c) # 2, 0
d) none of the mentioned 2
d)
Note: Join free Sanfoundry classes at Telegram or Youtube 0, 0
3. The operator used to access member function of a class? 0
a) :
b) ::
c) . 7. If a class inheriting an abstract class does not define all of its functions
d) # then it is known as?
a) Abstract
4. What is the most specified using class declaration? b) A simple class
a) type c) Static class
b) scope d) None of the mentioned
c) type & scope
d) none of the mentioned 8. Which of the following modifiers is used when an abstract method is
redefined by a derived class?
5. What will be the output of the following C# code? a) Overloads
1. class sample b) Override
2. { c) Base
3. public int i; d) Virtual
4. public int j;
5. public void fun(int i, int j) 9. What will be the output of the following C# code?
6. { 1. namespace ConsoleApplication4
7. this.i = i; 2. {
8. this.j = j; 3. public abstract class A
9. } 4. {
10. } 5. public int i = 7;
11. class Program 6. public abstract void display();
12. { 7. }
67
13. static void Main(string[] args) 8. class B: A
14. { 9. {
15. sample s = new sample(); 10. public int j;
16. s.i = 1; 11. public override void display()
17. s.j = 2; 12. {
18. s.fun(s.i, s.j); 13. Console.WriteLine(i);
19. Console.WriteLine(s.i + " " + s.j); 14. Console.WriteLine(j);
20. Console.ReadLine(); 15. }
21. } 16. }
22. } 17. class Program
a) Error while calling s.fun() due to inaccessible level 18. {
b) Error as ‘this’ reference would not be able to call ‘i’ and ‘j’ 19. static void Main(string[] args)
c) 1 2 20. {
d) Runs successfully but prints nothing 21. B obj = new B();
22. A obj1 = new B();
6. Which of the following statements about objects in “C#” is correct? 23. obj.j = 1;
a) Everything you use in C# is an object, including Windows Forms and 24. obj1.i = 8;
controls 25. obj.display();
b) Objects have methods and events that allow them to perform actions 26. Console.ReadLine();
c) All objects created from a class will occupy equal number of bytes in 27. }
memory 28. }
d) All of the mentioned 29. }
a) 0, 8
7. “A mechanism that binds together code and data in manipulates, and b) 1, 8
keeps both safe from outside interference and misuse. In short it isolates a c) 1, 7
particular code and data from all other codes and data. A well-defined d) 7, 1
interface controls access to that particular code and data.”
a) Abstraction 10. What will be the output of the following C# code?
b) Polymorphism 1. namespace ConsoleApplication4
c) Inheritance 2. {
d) Encapsulation 3. class A
4. {
8. What will be the output of the following C# code? 5. public int i;
1. class z 6. public void display()
2. { 7. {
3. public int X; 8. Console.WriteLine(i);
4. public int Y; 9. }
5. public const int c1 = 5; 10. }
6. public const int c2 = c1 * 25; 11. class B: A
7. public void set(int a, int b) 12. {
8. { 13. public int j;
9. X = a; 14. public void display()
10. Y = b; 15. {
11. } 16. Console.WriteLine(j);
12. 17. }
68
13. } 18. }
14. class Program 19. class Program
15. { 20. {
16. static void Main(string[] args) 21. static void Main(string[] args)
17. { 22. {
18. z s = new z(); 23. B obj = new B();
19. s.set(10, 20); 24. obj.j = 1;
20. Console.WriteLine(s.X + " " + s.Y); 25. obj.i = 8;
21. Console.WriteLine(z.c1 + " " + z.c2); 26. obj.display();
22. Console.ReadLine(); 27. Console.ReadLine();
23. } 28. }
24. } 29. }
a) 30. }
10 20 a) 8, 1
5 25 b) 8
b) c) 1
20 10 d) 1, 8
25 5 Interfaces Introduction
c) 1. Which statement correctly defines Interfaces in C#.NET?
10 20 a) Interfaces cannot be inherited
5 125 b) Interfaces consists of data static in nature and static methods
d) c) Interfaces consists of only method declaration
20 10 d) None of the mentioned
125 5
2. Which of the following cannot be used to declare an interface correctly?
a) Properties
9. Correct way of declaration of object of the following class is? b) Methods
class name c) Structures
a) name n = new name(); d) Events
b) n = name();
c) name n = name(); 3. A class consists of two interfaces with each interface consisting of three
d) n = new name(); methods. The class had no instance data. Which of the following indicates
the correct size of object created from this class?
10. The data members of a class by default are? a) 12 bytes
a) protected, public b) 16 bytes
b) private, public c) 0 bytes
c) private d) 24 bytes
d) public
advertisement
11. What will be the output of the following C# code? 4. Which of the following statements correctly define about the
1. class z implementation of interface?
2. { a) The calls to implementation of interface methods are routed through a
3. public string name1; method table
4. public string address; b) A class which implements an interface can explicitly implement members
5. public void show() of that interface
69
6. { c) One interface can be implemented in another interface
7. Console.WriteLine("{0} is in city{1}", name1, " ", address); d) None of the mentioned
8. }
9. } 5. Select the correct statement among the given statements?
10. class Program a) One class could implement only one interface
11. { b) Properties could be declared inside an interface
12. static void Main(string[] args) c) Interfaces cannot be inherited
13. { d) None of the mentioned
14. z n = new z();
15. n.name1 = "harsh"; Note: Join free Sanfoundry classes at Telegram or Youtube
16. n.address = "new delhi"; 6. Which keyword is used for correct implementation of an interface in
17. n.show(); C#.NET?
18. Console.ReadLine(); a) interface
19. } b) Interface
20. } c) intf
a) Syntax error d) Intf
b) {0} is in city{1} harsh new delhi
c) harsh is in new delhi 7. Choose the statements which makes interface different from classes?
d) Run successfully prints nothing a) Unlike classes, interfaces consists of only declaration but not
implementation
12. What does the following C# code imply? b) Interfaces cannot be used directly like classes to create new objects
csharp abc; c) Interfaces consists of declaration of methods, properties events and type
abc = new charp(); definitions
a) Object creation on class csharp d) All of the mentioned
b) Create an object of type csharp on heap or on stack depending on the
size of object 8. Which of the following is the correct way of implementing an interface
c) create a reference c on csharp and an object of type csharp on heap addition by class maths?
d) create an object of type csharp on stack a) class maths : addition {}
b) class maths implements addition {}
13. What will be the output of the following C# code? c) class maths imports addition {}
1. class test d) none of the mentioned
2. {
3. public void print() 9. Does C#.NET support partial implementation of interfaces?
4. { a) True
5. Console.WriteLine("Csharp:"); b) False
6. } c) Can’t Say
7. } d) None of the mentioned
8. class Program
9. { 10. Select the correct implementation of the interface which is mentioned
10. static void Main(string[] args) below.
11. { 1. interface a1
12. test t; 2. {
13. t.print(); 3. int fun(int i);
14. Console.ReadLine(); 4. }
15. } a)
70
16. } 1. class a
a) Code runs successfully prints nothing 2. {
b) Code runs and prints “Csharp” 3. int fun(int i) as a1.fun
c) Syntax error as t is unassigned variable which is never used 4. {
d) None of the mentioned 5. }
Reference Variables and Assignment 6. }
1. Which reference modifier is used to define reference variable? b)
a) & 1. class a: implements a1
b) ref 2. {
c) # 3. int fun(int i)
d) $ 4. {
5. }
2. What will be the output of the following C# code? 6. }
1. static void Main(string[] args) c)
2. { 1. class a: a1
3. int a = 5; 2. {
4. fun1 (ref a); 3. int a1.fun(int i)
5. Console.WriteLine(a); 4. {
6. Console.ReadLine(); 5. }
7. } 6. }
8. static void fun1(ref int a) d) None of the mentioned
9. {
10. a = a * a; 11. Which of these can be used to fully abstract a class from its
11. } implementation?
a) 5 a) Objects
b) 0 b) Packages
c) 20 c) Interfaces
d) 25 d) None of the Mentioned

3. What will be the output of the following C# code? 12. Access specifiers which can be used for an interface are?
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. a) Public
Participate Now! b) Protected
1. static void Main(string[] args) c) Private
2. { d) All of the mentioned
3. int[] arr = new int[] {1, 2, 3, 4, 5};
4. fun1(ref arr); Interfaces Implementation
5. Console.ReadLine(); 1. What will be the Correct statement in the following C# code?
6. } 1. interface a1
7. static void fun1(ref int[] array) 2. {
8. { 3. void f1();
9. for (int i = 0; i < array.Length; i++) 4. int f2();
10. { 5. }
11. array[i] = array[i] + 5; 6. class a :a1
12. Console.WriteLine(array[i] + " "); 7. {
13. } 8. void f1()
71
14. } 9. {
a) 6 7 8 9 10 10. }
b) 15 17 8 8 20 11. int a1.f2()
c) 15 17 8 29 20 12. {
d) Syntax error while passing reference of array variable 13. }
14. }
4. What will be the output of the following C# code? a) class a is an abstract class
1. static void Main(string[] args) b) A method table would not be created for class a
2. { c) The definition of f1() in class a should be void a1.f1()
3. int a = 10 , b = 20; d) None of the mentioned
4. Console.WriteLine("Result before swap is: "+ a +" "+b);
5. swap(ref a, ref b); advertisement
6. Console.ReadLine(); 2. Choose the wrong statement about ‘INTERFACE’ in C#.NET?
7. } a) An explicitly implemented member could be accessed from an instance of
8. static void swap(ref int i, ref int j) the interface
9. { b) Interfaces are declared public automatically
10. int t; c) An interface could not contain signature of the indexer
11. t = i; d) None of the mentioned
12. i = j;
13. j = t; 3. What will be the Correct statement in the following C# code?
14. Console.WriteLine("Result after swap is:"+ i +" "+j); Note: Join free Sanfoundry classes at Telegram or Youtube
15. } 1. interface a1
a) 2. {
Result before swap is: 20 10 3. void f1();
Result after swap is: 20 10 4. void f2();
b) 5. }
Result before swap is: 10 20 6. class a :a1
Result after swap is:20 10 7. {
c) 8. private int i;
Result before swap is: 10 20 9. void a1.f1()
Result after swap is:10 20 10. {
d) 11. }
Result before swap is: 20 10 12. }
Result after swap is:10 20 a) Class a could not have an instance data
b) Class a is an abstract class
c) Class a fully implements the interface a1
5. What will be the output of the following C# code? d) None of the mentioned
1. static void Main(string[] args)
2. { 4. What will be the Correct statement in the following C# code?
3. int []a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; 1. interface abc
4. func(ref a); 2. {
5. Console.ReadLine(); 3. String FirstName
6. } 4. {
7. static void func(ref int[] x) 5. get;
8. { 6. set;
72
9. Console.WriteLine(" numbers are:"); 7. }
10. for (int i = 0; i < x.Length; i++) 8. String LastName
11. { 9. {
12. if (x[i] % 2 == 0) 10. get;
13. { 11. set;
14. x[i] = x[i] + 1; 12. }
15. Console.WriteLine(x[i]); 13. void print();
16. } 14. void stock();
17. } 15. int fun();
18. } 16. }
a) numbers are : 2 4 6 8 10 a) Functions should be declared inside an interface
b) numbers are : 3 5 7 9 11 b) It is workable code
c) numbers are : 2 3 4 5 6 c) Properties cannot be declared inside an interface
d) none of the mentioned d) None of the mentioned

6. Select the wrong statement about ‘ref’ keyword in C#? 5. What will be the output of the following C# code?
a) References can be called recursively 1. interface calc
b) The ‘ref’ keyword causes arguments to be passed by reference 2. {
c) When ‘ref’ are used, any changes made to parameters in method will be 3. void cal(int i);
reflected in variable when control is passed back to calling method 4. }
d) All of the mentioned 5. public class maths :calc
6. {
7. Select correct differences between ‘=’ and ‘==’ in C#. 7. public int x;
a) 8. public void cal(int i)
'==' operator is used to assign values from one variable to another variable 9. {
'=' operator is used to compare value between two variables 10. x = i * i;
b) 11. }
'=' operator is used to assign values from one variable to another variable 12. }
'==' operator is used to compare value between two variables 13. class Program
c) No difference between both operators 14. {
d) None of the mentioned 15. public static void Main(string[] args)
16. {
8. What will be the output of the following C# code? 17. display arr = new display();
1. static void Main(string[] args) 18. arr.x = 0;
2. { 19. arr.cal(2);
3. int X = 0; 20. Console.WriteLine(arr.x);
4. if (Convert.ToBoolean(X = 0)) 21. Console.ReadLine();
5. Console.WriteLine("It is zero"); 22. }
6. else 23. }
7. Console.WriteLine("It is not zero"); a) 0
8. Console.ReadLine(); b) 2
9. } c) 4
a) It is zero d) None of the mentioned
b) It is not zero
c) Infinite loop 6. What will be the output of the following C# code?
73
d) None of the mentioned 1. interface calc
2. {
9. What will be the output of the following C# code? 3. void cal(int i);
1. static void Main(string[] args) 4. }
2. { 5. class displayA :calc
3. int X = 6,Y = 2; 6. {
4. X *= X / Y; 7. public int x;
5. Console.WriteLine(X); 8. public void cal(int i)
6. Console.ReadLine(); 9. {
7. } 10. x = i * i;
a) 12 11. }
b) 6 12. }
c) 18 13. class displayB :calc
d) Compile time error 14. {
15. public int x;
10. What will be the output of the following C# code? 16. public void cal(int i)
1. static void Main(string[] args) 17. {
2. { 18. x = i / i;
3. int x = 4 ,b = 2; 19. }
4. x -= b/= x * b; 20. }
5. Console.WriteLine(x + " " + b); 21. class Program
6. Console.ReadLine(); 22. {
7. } 23. public static void Main(string[] args)
a) 4 2 24. {
b) 0 4 25. displayA arr1 = new displayA();
c) 4 0 26. displayB arr2 = new displayB();
d) 2 2 27. arr1.x = 0;
28. arr2.x = 0;
11. What will be the output of the following C# expression? 29. arr1.cal(2);
int a+= (float) b/= (long)c. 30. arr2.cal(2);
a) float 31. Console.WriteLine(arr1.x + " " + arr2.x);
b) int 32. Console.ReadLine();
c) long 33. }
d) none of the mentioned 34. }
a) 0 0
12. What will be the output of the following C# code? b) 2 2
1. static void Main(string[] args) c) 4 1
2. { d) 1 4
3. int x = 8;
4. int b = 16; 7. What will be the output of the following C# code?
5. int C = 64; 1. interface i1
6. x /= b /= C; 2. {
7. Console.WriteLine(x + " " + b+ " " +C); 3. void fun();
8. Console.ReadLine(); 4. }
9. } 5. interface i2
74
a) 8 2 32 6. {
b) 32 4 8 7. void fun();
c) 32 2 8 8. }
d) Compile time error 9. public class maths :i1, i2
10. {
13. What will be the output of the following C# code? 11. void i1.fun()
1. static void Main(string[] args) 12. {
2. { 13. Console.WriteLine("i1.fun");
3. int x = 8; 14. }
4. int b = 16; 15. void i2.fun()
5. int C = 64; 16. {
6. x /= b /= C /= x; 17. Console.WriteLine("i2.fun");
7. Console.WriteLine(x + " " + b+ " " +C); 18. }
8. Console.ReadLine(); 19. }
9. } 20. class Program
a) 8 2 4 21. {
b) 2 4 8 22. static void Main(string[] args)
c) 4 2 8 23. {
d) Compile time error 24. Sample obj = new Sample();
– Methods in Class 25. i1 i = (i1) obj;
1. What will be the output of the following C# code? 26. i.fun();
1. static void Main(string[] args) 27. i2 ii = (i2) obj;
2. { 28. ii.fun();
3. int a = 5; 29. }
4. int s = 0, c = 0; 30. }
5. Mul (a, ref s, ref c); a) i1.fun
6. Console.WriteLine(s + "t " +c); b)
7. Console.ReadLine(); i2.fun
8. } i1.fun
9. static void Mul (int x, ref int ss, ref int cc) c) 0
10. { d)
11. ss = x * x; i1.fun
12. cc = x * x * x; i2.fun
13. }
a) 125 25
b) 25 125
c) Compile time error 8. What will be the correct way to implement the interface in the following
d) 0 0 C# code?
1. interface abc
2. Which of the following statements are correct about functions? 2. {
a) C# allows a function to have arguments with default values 3. string name
b) Redefining a method parameter in the method’s body causes an exception 4. {
c) C# allows function to have arguments with default values 5. get;
d) Omitting the return type in method definition results into exception 6. set;
7. }
75
Subscribe Now: C# Newsletter | Important Subjects Newsletters 8. }
3. What will be the output of the following C# code? a)
1. static void Main(string[] args) class emp :employee
2. { {
3. Mul(); private string str;
4. m(); public string firstname;
5. Console.ReadLine(); {
6. } get
7. static void Mul() {
8. { return str;
9. Console.WriteLine("4"); }
10. } set
11. static void m() {
12. { str = value;
13. Console.WriteLine("3"); }
14. Mul(); }
15. } }
a) 4 3 3 b)
b) 4 4 3 class emp :implements person
c) 4 3 4 {
d) 3 4 4 private string str;
public string firstname
4. What will be the output of the following C# code? {
1. static void Main(string[] args) get
2. { {
3. m(); return str;
4. Console.ReadLine(); }
5. } set
6. static void m() {
7. { str = value;
8. Console.WriteLine("HI"); }
9. m(); }
10. } }
a) HI HI HI c)
b) HI class emp: implements person
c) Stack overflow exception {
d) Compile time error private string str;
public string person.firstname
5. When a function fun() is to receive an int, a single & a double and it is to {
return a decimal, then the correct way of defining this C# function is? get
a) {
static fun(int i, single j, double k) return str;
{ }
return decimal; set
} {
76
b) str = value;
static decimal fun(int i, single, double k) }
{ }
}
} d) None of the mentioned
c)
decimal fun(int i, single j, double k) 9. What will be the output of the following C# code?
{ 1. interface i1
2. {
} 3. void f1();
d) 4. }
decimal static fun(int i, single j, double k) 5. interface i2 :i1
{ 6. {
7. void f2();
} 8. }
9. public class maths :i2
10. {
6. What will be the output of the following C# code? 11. public void f2()
1. static void Main(string[] args) 12. {
2. { 13. Console.WriteLine("fun2");
3. int i = 10; 14. }
4. double d = 35.78; 15. public void f1()
5. fun(i); 16. {
6. fun(d); 17. Console.WriteLine("fun1");
7. Console.ReadLine(); 18. }
8. } 19. }
9. static void fun(double d) 20. class Program
10. { 21. {
11. Console.WriteLine(d); 22. static Void Main()
12. } 23. {
a) 24. maths m = new maths();
35.78 25. m.f1();
10 26. m.f2();
b) 27. }
10 28. }
35.00 a) fun2
c) b) fun1
10 c)
35.78 fun1
d) None of the mentioned fun2
d)
7. How many values does a function return? fun2
a) 0 fun1
b) 2 10. In order to avoid ambiguity among an interface derived from two base
c) 1 interfaces with same method name(and signature), the right code among
77
d) any number of values the following C# codes is?
a)
8. What will be the output of the following C# code? 1. interface i1
1. static void Main(string[] args) 2. {
2. { 3. void m1();
3. int y = 3; 4. }
4. y++; 5. interface i2
5. if (y <= 5) 6. {
6. { 7. void m1();
7. Console.WriteLine("hi"); 8. }
8. Main(args); 9. interface i3 :i1, i2
9. } 10. {
10. Console.ReadLine(); 11. }
11. } 12. class c3 :i3
a) hi hi 13. {
b) hi 14. void i1.m1()
c) Stack overflow exception 15. {
d) None of the mentioned 16. }
17. void i1.m1()
9. Which return statement correctly returns the output? 18. {
a) 19. }
public int cube(int x) 20. }
{ b)
return (x + x); interface i1
} {
b) void m1();
public int cube(int x) }
return (x + x); interface i2
c) {
public int cube(int x) void m1();
{ }
return x + x; interface i3 :i1, i2
} {
d) None of the mentioned }
class c3 :i3
10. What will be the output of the following C# code? {
1. public static void Main(string[] args) void i1.i2.m1()
2. { {
3. p(); }
4. void p() }
5. { c)
6. Console.WriteLine("hi"); interface i1
7. } {
8. } void m1();
a) Compile time error }
78
b) hi interface i2
c) hi infinite times {
d) None of the mentioned void m1();
Constructors in Class }
1. Number of constructors a class can define is? interface i3 :i1, i2
a) 1 {
b) 2 }
c) Any number class c3 :i3
d) None of the mentioned {
void i1.m1()
2. The correct way of defining constructor of the given class as and when {
objects of classes are created is: }
maths s1 = new maths(); void i2.m1()
maths s2 = new maths(5, 5.4f); {
a) }
advertisement }
public maths(int pp, single tt) d) All of the mentioned
{
p = pp; Introduction of Overloaded Operators
t = tt; 1. Which of the following keyword is used to overload user defined types by
} defining static member functions?
b) sample s; a) op
c) b) opoverload
Subscribe Now: C# Newsletter | Important Subjects Newsletters c) operator
public sample() d) operatoroverload
{
p = 0; 2. Which of the following statements are correct in nature?
t = 0.0f; a) The conditional logical operators cannot be overloaded
} b) The array indexing operator can be overloaded
public sample(int pp, single tt) c) A public or nested public preference type does not overload the equality
{ operator
p = pp; d) None of the mentioned
t = tt;
} 3. Arrange the following overloaded operators in increasing order of
d) s = new sample(); precedence?
advertisement
3. Correct way to define object of sample class in which C# code will work %, <<, &, /, +
correctly is: a) ‘%’ < ‘<<‘ < ‘+’ < ‘-‘ < ‘&’ < ‘/’
1. class abc b) ‘<<‘ < ‘&’ < ‘%’ < ‘-‘ < ‘/’ < ‘+’
2. { c) ‘&’ < ‘-‘ <‘%’ < ‘<<‘ < ‘/’ < ‘+’
3. int i; d) ‘/’ < ‘-‘ < ‘%’ < ‘+’ < ‘<<‘ < ‘&’
4. float k;
5. public abc(int ii, float kk) Sanfoundry Certification Contest of the Month is Live. 100+ Subjects.
6. { Participate Now!
7. i = ii; 4. Operators that can be overloaded are?
79
8. k = kk; a) ||
9. } b) ‘+=’
10. } c) +
a) abc s1 = new abc(1); d) []
b) abc s1 = new abc();
c) abc s2 = new abc(1.4f); 5. Which statements are correct about operator overloading?
d) abc s2 = new abc(1, 1.4f); a) Mathematical or physical modeling where we use classes to represent
objects such as vectors, matrices, complex-numbers etc
4. Correct statement about constructors in C#.NET is? b) Graphical programs where coordinate related objects are used to
a) Constructors can be overloaded represent positions on the screen
b) Constructors are never called explicitly c) Financial programs where a class represents an amount of money
c) Constructors have same name as name of the class d) All of the mentioned
d) All of the mentioned
6. Correct way to define operator method or to perform operator overloading
5. Which among the following is the correct statement: Constructors are used is?
to? a)
a) initialize the objects 1. public static op(arglist)
b) construct the data members 2. {
c) initialize the objects & construct the data members 3.
d) none of the mentioned 4. }
b)
6. Can the method add() be overloaded in the following ways in C#? 1. public static retval op(arglist)
public int add() { } 2. {
public float add(){ } 3.
a) True 4. }
b) False c)
1. public static retval operator op(arglist)
7. Which of the following statements is correct about constructors in 2. {
C#.NET? 3.
a) A constructor cannot be declared as private 4. }
b) A constructor cannot be overloaded d) All of the mentioned
c) A constructor can be a static constructor
d) None of the mentioned 7. Correct method to define + operator is?
a) public sample operator +(int a, int b)
8. What will be the output of the following C# code? b) public abstract operator +(int a, int b)
1. class abc c) public static sample operator +(int a, int b)
2. { d) public abstract sample operator +(int a, int b)
3. public static void a()
4. { 8. Choose the correct statement among the below mentioned statements.
5. console.writeline("first method"); a) Forgetting to declare an operator method as public
6. } b) Forgetting to declare an operator method as static
7. public void b() c) Forgetting to return a bool type value while overloading a relational
8. { operator
9. a(); d) All of the mentioned
10. console.writeline("second method");
80
11. } 9. What is the vector in operator overloading?
12. public void b(int i) a) class
13. { b) method()
14. console.writeline(i); c) data type
15. b(); d) none of the mentioned
16. }
17. } 10. Choose the wrong statement from the given set of statements?
18. class program a) All operators in C#.NET cannot be overloaded
19. { b) We can use the new modifier to modify a nested type if the nested type is
20. static void main() hiding another type
21. { c) Operator overloading permits the use of symbols to represent
22. abc k = new abc(); computations for a type
23. abc.a(); d) In case of operator overloading all parameters must be of different type
24. k.b(20); than the class or struct that declares the operators
25. } Recursion
26. } 1. What is Recursion in CSharp defined as?
a) a) Recursion is another form of class
second method b) Recursion is another process of defining a method that calls other
20 methods repeatedly
second method c) Recursion is a process of defining a method that calls itself repeatedly
first method d) Recursion is a process of defining a method that calls other methods
b) which in turn calls this method
first method
20 2. Which of these will happen if the recursive method does not have a base
first method case?
second method a) Infinite loop condition occurrence
c) b) System gets hanged
first method c) After 10000 executions program will be automatically stopped
20 d) None of the mentioned
d)
second method 3. Which of these is not a correct statement?
20 a) A recursive method must have a base case
first method b) Recursion always uses stack
c) Recursion is always managed by C# Runtime environment
d) Recursive methods are faster that programmer written loop to call the
9. What is the return type of constructors? function repeatedly using a stack
a) int
b) float advertisement
c) void 4. What will be the output of the following C# code?
d) none of the mentioned 1. class recursion
2. {
10. Which method has the same name as that of its class? 3. int fact(int n)
a) delete 4. {
b) class 5. int result;
c) constructor 6. if (n == 1)
81
d) none of the mentioned 7. return 1;
– Destructors in Class 8. result = fact(n - 1) * n;
1. Which operator among the following signifies the destructor operator? 9. return result;
a) :: 10. }
b) : 11. }
c) ~ 12. class Program
d) & 13. {
14. public static void main(String args[])
2. The method called by clients of a class to explicitly release any resources 15. {
like network, connection, open files etc. When the object is no longer 16. recursion obj = new recursion() ;
required? 17. Console.WriteLine(obj.fact(4));
a) Finalize() 18. }
b) End() 19. }
c) Dispose() a) 24
d) Close() b) 30
c) 120
3. Name a method which has the same name as that of class and which is d) 144
used to destroy objects also called automatically when application is finally
on process of being getting terminated. Sanfoundry Certification Contest of the Month is Live. 100+ Subjects.
a) Constructor Participate Now!
b) Finalize() 5. What will be the output of the following C# code?
c) Destructor 1. class maths
d) End 2. {
3. int fact(int n)
advertisement 4. {
4. Which of the following statements are correct? 5. int result;
a) There is one garbage collector per program running in memory 6. if (n == 1)
b) There is one common garbage collector for all programs 7. return 1;
c) To garbage collect an object set all references to it as null 8. result = fact(n - 1) * n;
d) Both There is one common garbage collector for all programs & To 9. return result;
garbage collect an object set all references to it as null 10. }
11. }
5. Operator used to free the memory when memory is allocated? 12. class Output
a) new 13. {
b) free 14. static void main(String args[])
c) delete 15. {
d) none of the mentioned 16. maths obj = new maths() ;
17. Console.WriteLine(obj.fact(1));
Note: Join free Sanfoundry classes at Telegram or Youtube 18. }
6. Select wrong statement about destructor in C#? 19. }
a) A class can have one destructor only a) 2
b) Destructors cannot be inherited or overloaded b) 10
c) Destructors can have modifiers or parameters c) 1
d) All of the mentioned d) 0

82
7. What will be the output of the following C# code? 6. What will be the output of the following C# code snippet?
1. class sample 1. class maths
2. { 2. {
3. int i; 3. int fact(int n)
4. double k; 4. {
5. public sample (int ii, double kk) 5. int result;
6. { 6. if (n == 1)
7. i = ii; 7. return 1;
8. k = kk; 8. result = fact(n - 1) * n;
9. double j = (i) + (k); 9. return result;
10. Console.WriteLine(j); 10. }
11. } 11. }
12. ~sample() 12. class Output
13. { 13. {
14. double j = i - k; 14. static void main(String args[])
15. Console.WriteLine(j); 15. {
16. } 16. maths obj = new maths() ;
17. } 17. Console.WriteLine(obj.fact(4)*obj.fact(2));
18. class Program 18. }
19. { 19. }
20. static void Main(string[] args) a) 64
21. { b) 60
22. sample s = new sample(8, 2.5); c) 120
23. Console.ReadLine(); d) 48
24. }
25. } 7. What will be the output of the following C# code?
a) 0 0 1. class maths
b) 10.5 0 2. {
c) Compile time error 3. int fact(int n)
d) 10.5 5.5 4. {
5. int result;
8. What is the return type of destructor? 6. if (n == 1)
a) int 7. return 1;
b) void 8. result = fact(n - 1) * n;
c) float 9. return result;
d) none of the mentioned 10. }
11. }
9. What will be the output of the following C# code? 12. class Output
1. class box 13. {
2. { 14. static void main(String args[])
3. public int volume; 15. {
4. int width; 16. maths obj = new maths() ;
5. int height; 17. Console.WriteLine(obj.fact(4)*(3));
6. int length; 18. }
7. public box ( int w, int h, int l) 19. }
83
8. { a) 64
9. width = w; b) 60
10. height = h; c) 72
11. length = l; d) 84
12. }
13. public ~box() 8. Which of these data types is used by the operating system to manage the
14. { Recursion in Csharp?
15. volume = width * length * height; a) Array
16. b) Queue
17. } c) Tree
18. d) Stack
19. }
20. class Program 9. What will be the output of the following C# code snippet?
21. { 1. class maths
22. static void Main(string[] args) 2. {
23. { 3. public int fact(int n)
24. box b = new box(4, 5, 9); 4. {
25. Console.WriteLine(b.volume); 5. int result;
26. Console.ReadLine(); 6. result = fact(n - 1) * n;
27. } 7. return result;
28. 8. }
29. } 9. }
a) 0 10. class Program
b) 180 11. {
c) Compile time error 12. static void Main(string[] args)
d) None of the mentioned 13. {
14. maths obj = new maths();
10. What will be the output of the following C# code? 15. Console.WriteLine(obj.fact(4));
1. class box 16. Console.ReadLine();
2. { 17. }
3. public int volume; 18. }
4. int width; a) 24
5. int height; b) 30
6. int length; c) Compile time error
7. public box ( int w, int h, int l) d) Runtime Error
8. {
9. this.width = w; 10. What will be the output of the following C# code snippet?
10. this.height = h; 1. class maths
11. this.length = l; 2. {
12. } 3. public int fact(int n)
13. ~ box() 4. {
14. { 5. int result;
15. volume = this.width * this.length * this.height; 6. if (n == 2)
16. console.writeline(volume); 7. return 1;
17. } 8. result = fact(n - 1) * n;
84
18. } 9. return result;
19. class Program 10. }
20. { 11. }
21. public static void Main(string[] args) 12. class Program
22. { 13. {
23. box b = new box(4, 5, 9); 14. static void Main(string[] args)
24. Console.ReadLine(); 15. {
25. } 16. maths obj = new maths();
26. } 17. Console.WriteLine(obj.fact(4));
a) 0 18. Console.ReadLine();
b) Code executes successfully but prints nothing 19. }
c) Compile time error 20. }
d) 180 a) 24
Arrays and Strings b) 0
Array c) 12
1. What will be the output of the following C# code? d) 1
1. static void Main(string[] args)
2. {
Introduction of Indexers
3. int i, j; 1. Choose the correct statement among the followings?
4. int[, ] arr = new int[ 3, 3]; a) Indexers are location indicators
5. for (i = 0; i < 3; ++i) b) Indexers are used to access class objects
6. {
c) Indexer is a form of property and works in the same way as a
7. for (j = 0; j < 3; ++j)
8. { property
9. arr[i, j] = i * 2 + i * 2; d) All of the mentioned
10. Console.WriteLine(arr[i, j]);
11. } 2. Choose the keyword which declares the indexer?
12. Console.ReadLine();
a) base
13. }
14. } b) this
a) 0, 0, 0 4, 4, 4 8, 8, 8 c) super
b) 4, 4, 4 8, 8, 8 12, 12, 12 d) extract
c) 8, 8, 8 12, 12, 12 16, 16, 16
d) 0, 0, 0 1, 1, 1 2, 2, 2
3. Choose the operator/operators which is/are not used to access the
2. What will be the output of the following C# code? [] operator in indexers?
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. a) get
Participate Now! b) set
1. static void Main(string[] args)
c) access
2. {
3. char A = 'K'; d) all of the mentioned
4. char B = Convert.ToChar(76);
5. A++; 4. Choose the correct statement among the following?
6. B++; a) A property can be a static member whereas an indexer is always
7. Console.WriteLine(A+ " " +B);
85
8. Console.ReadLine(); an instance member
9. } b) A get accessor of a property corresponds to a method with no
a) M L
b) U L parameters whereas get accessor of an indexer corresponds to a
c) L M method with the same formal parameters lists as the indexer
d) A B c) It is an error for indexer to declare a local variable with the same
name as indexer parameters
3. Complete the following C# code with “foreach condition”.
1. int[][]a = new int[2][]; d) All of the mentioned
2. a[0] = new int[3]{3, 4, 2}; 5. For a class student consisting of indexer, which among the
3. a[1] = new int[2]{8, 5}; following declaration of indexers runs the C# code successfully?
4. foreach( int[]i in a)
5. {
6. /* add for loop */ student a = new student();
7. console.write( j+ " "); a[1,2] = 20;
8. console.writeline(); a)
9. }
a) foreach (int j = 1;(j(<)(a(0).GetUpperBound)); (j++));
b) foreach (int j = 1;(j(<)(a.GetUpperBound(0))); (j++)); class student
c) foreach (int j in a.Length); {
d) foreach (int j in i); int[,] p = new int[6, 6];
public property WriteOnly int this[int i, int j]
4. What will be the output of the following C# code?
{
1. static void Main(string[] args)
2. { set
3. double a = 345.09; {
4. byte c = (byte) a; a[i, j] = value;
5. Console.WriteLine(c); }
6. Console.ReadLine();
}
7. }
}
a) 98
b) 89 b)
c) 88
d) 84
class student

5. Which statement is correct about following c#.NET code? {


int[] a= {11, 3, 5, 9, 6}; int[,] a = new int[6, 6];
a) ‘a’ is a reference to the array created on stack public int this[int i, int j]
b) ‘a’ is a reference to an object created on stack {
c) ‘a’ is a reference to an object of a class that compiler drives from set
‘System.Array’ class
{
d) None of the mentioned
a[i, j] = value;
6. What is the advantage of using 2D jagged array over 2D rectangular }
array? }
86
a) Easy initialization of elements }
b) Allows unlimited elements as well as rows which had ‘0’ or are empty in c)
nature
c) All of the mentioned
d) None of the mentioned class student
{
7. Which statement is correct about following C# code? int[,] a = new int[6, 6];
int[, ]a={{5, 4, 3},{9, 2, 6}};
public int property WriteOnly
a)’a’ represents 1-D array of 5 integers
b) a.GetUpperBound(0) gives 9 {
c)’a’ represents rectangular array of 2 columns and 3 arrays set
d) a.GetUpperBound(0) gives 2 {
a[i, j] = value;
8. What will be the output of the following C# code?
}
1. static void Main(string[] args)
2. { }
3. Program p = new Program(); }
4. p.display(2, 3, 8); d) None of the mentioned
5. int []a = { 2, 56, 78, 66 };
6. Console.WriteLine("example of array"); 6. Which among the following are the advantages of using indexers?
7. Console.WriteLine("elements added are");
8. p.display(a); a) To use collection of items at a large scale we make use of indexers
9. Console.ReadLine(); as they utilize objects of class that represent the collection as an
10. } array
11. public void display(params int[] b) b) Indexers are also convenient as they can also make use of
12. {
13. foreach (int i in b)
different types of indexers like int, string etc
14. { c) An indexer allows an object to be indexed such as an array
15. Console.WriteLine("ARRAY IS HAVING:{0}", i); d) All of the mentioned
16. }
17. } 7. Choose the correct statement about properties describing the
a) Compile time error
b) Run time error indexers?
c) Code runs successfully but prints nothing a) No need to use the name of the property while using an indexed
d) Code runs successfully and prints given on console property
b) An indexer property should accept at least one argument
c) Indexers can be overloaded
d) All of the mentioned

8. Choose the correct alternative that utilizes the indexed property


such that a group named class has indexed property which stores or
retrieves value to/from an array of 5 numbers?
a) group[3] = 34;
87
b) group g = group();
c) Console.WriteLine(group[3]);
d)

group g = new group();

Console.WriteLine(g[3]);

9. Choose the correct option among the following indexers which


correctly allows to index in same way as an array?
a) A class
b) An interface
c) A function
d) A property

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

1. class list
2. {
3. ArrayList array = new ArrayList();
4. public object this[int index]
5. {
6. get
7. {
8. if (index < 0 || index >= array.Count)
9. {
10. return null;
11. }
12. else
13. {
14. return (array[index]);
15. }
16. }
17. set
18. {
88
19. array[index] = value;
20. }
21. public int Count
22. {
23. get;
24. set;
25. }}
26. class Program
27. {
28. static void Main(string[] args)
29. {
30. list list1 = new list();
31. list1[0] = "123";
32. list1[1] = " abc ";
33. list1[2] = "xyz";
34. for (int i = 0; i<=list1.Count; i++)
35. Console.WriteLine(list1[i]);
36. Console.ReadLine();
37. }
38. }
a) Compile time error
b) Run time error
c) 123, abc, xyz
d) 0

89

You might also like