Arrays And Strings In C Sharp

Name: _____________________

Date: _____________________

Instructions: Answer all questions. Write your answers clearly in the space provided.

Question 1:

Which of these access specifiers must be used for main() method?

A. private
B. public
C. protected
D. none of the mentioned
Answer: _________
Question 2:

Which of these methods of the class String is used to obtain length of String object?

A. get()
B. Sizeof()
C. lengthof()
D. length()
Answer: _________
Question 3:

Which of these data type values is returned by equals() method of String class?

A. char
B. int
C. boolean
D. all of the mentioned
Answer: _________
Question 4:

Correct way to convert a string to uppercase using string class method()?

A. Upper()
B. ToUpper()
C. Object.ToUpper()
D. None of the mentioned
Answer: _________
Question 5:

Which of the following statements is true regarding arrays in C#?

A. Arrays in C# can dynamically resize
B. The length of an array cannot be changed
C. Arrays in C# can only store primitive types
D. None of the above
Answer: _________
Question 6:

Which method in C# is used to sort the elements of an array in ascending order?

A. Array.Sort()
B. Array.Reverse()
C. Array.Find()
D. Array.IndexOf()
Answer: _________
Question 7:

What does the 'Length' property of an array in C# return?

A. The number of characters in the array
B. The number of dimensions in the array
C. The size of the array in bytes
D. The total number of elements in the array
Answer: _________
Question 8:

Which of the following string() method are used to compare two strings with each other?

A. CopyTo()
B. Copy()
C. Compare()
D. CompareTo()
Answer: _________
Question 9:

Which statement is/are correct?

A. An argument passed to a ref parameter need not be initialized first
B. Variables passed as out arguments need to be initialized prior to being passed
C. To use a ref parameter, only the calling method must explicitly use the ref keyword
D. None of the mentioned
Answer: _________
Question 10:

Which of these methods of class String is used to compare two String objects for their equality?

A. equals()
B. Equals()
C. isequal()
D. Isequal()
Answer: _________
Question 11:

Which of these is used to access members of class before the object of that class is created?

A. public
B. private
C. static
D. protected
Answer: _________
Question 12:

What is the value returned by function compareTo() if the invoking string is less than the string compared?

A. zero
B. value less than zero
C. value greater than zero
D. none of the mentioned
Answer: _________
Question 13:

What does the term 'immutable' means in term of string objects?

A. We can modify characters included in the string
B. We cannot modify characters contained in the string
C. We cannot perform various operation of comparison, inserting, appending etc
D. None of the mentioned
Answer: _________
Question 14:

Accessibility modifier defined in a class are?

A. public, private, protected
B. public, internal, protected internal
C. public, private, internal, protected internal
D. public, private, protected, internal, protected internal
Answer: _________
Question 15:

Which of these methods is an alternative to getChars() that stores the characters in an array of bytes?

A. getBytes()
B. GetByte()
C. giveByte()
D. Give Bytes()
Answer: _________
Question 16:

The modifiers used to define an array of parameters or list of arguments is . . . . . . . .

A. ref
B. out
C. param
D. var
Answer: _________
Question 17:

Which of these methods of class String is used to separate a substring from a String object?

A. substring()
B. Substring()
C. SubString()
D. None of the mentioned
Answer: _________
Question 18:

Statements about 'ref' keyword used in C#.NET are?

A. The ref keyword causes arguments to be passed by reference
B. While using 'ref' keyword any changes made to the parameter in the method will be reflected in the variable when control is passed back to the calling method
C. Ref usage eliminates overhead of copying large data items
D. All of the mentioned
Answer: _________
Question 19:

Which of the following statement is correct about a string in C#.NET?

A. The System.Array class is used to represent a string
B. A string has a zero-based index
C. A number cannot be represented in the form of a string
D. A string is mutable because it can be modified once it has been created
Answer: _________
Question 20:

Which of these methods of class String is used to check whether a substring exists at the beginning of the particular string?

A. StartsWith()
B. EndsWith()
C. Starts()
D. ends()
Answer: _________
Question 21:

What is the String in C# meant for?

A. Variable
B. Character Array
C. Object
D. Class
Answer: _________
Question 22:

Which of these operators can be used to concatenate two or more String objects?

A. +
B. +=
C. &
D. ||
Answer: _________
Question 23:

Which of these is used as a default specifier for a member of the class if no access specifier is used for it?

A. private
B. public
C. public, within its own class
D. protected
Answer: _________
Question 24:

The method in which large or variable number of arguments are handled is known as . . . . . . . .

A. Value parameters
B. Output parameters
C. Parameter arrays
D. None of the mentioned
Answer: _________
Question 25:

Choose the statements which are false in nature?

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 class
C. Private members of the base class cannot be accessed by derived class member functions or objects of derived class
D. None of the mentioned
Answer: _________
Question 26:

Keyword used to define call by reference parameter in C# .NET?

A. &
B. out
C. ref
D. &&
Answer: _________
Question 27:

How is a string typically processed?

A. On a character by character basis
B. On a string by string basis
C. Both On a character by character basis & On a string by string basis
D. None of the mentioned
Answer: _________
Question 28:

What is the advantage of using 2D jagged array over 2D rectangular array?

A. Easy initialization of elements
B. Allows unlimited elements as well as rows which had '0' or are empty in nature
C. All of the mentioned
D. None of the mentioned
Answer: _________
Question 29:

Which of the following statements are correct?

A. C SHARP allows a function to have arguments with default values
B. C SHARP allows a function to have variable number of arguments
C. Params are used to specify the syntax for a function having arguments
D. Omitting the return value type in method definition results into an exception
E. String is value type
F. String literals can contain any character literal including escape sequences
G. The equality operators are defined to compare values of string objects as well as references
H. All of the mentioned
Answer: _________
Question 30:

Which of the following methods is used to concatenate strings in C#?

A. Merge()
B. Join()
C. Concat()
D. Add()
Answer: _________
Question 31:

Which method in C# is used to find the index of a specific element in an array?

A. Array.FindIndex()
B. Array.IndexOf()
C. Array.Search()
D. Array.Position()
Answer: _________
Question 32:

Which of the following statements is true regarding strings in C#?

A. Strings are not supported in C#
B. Strings can be resized dynamically
C. Strings can be modified directly
D. Strings are immutable
Answer: _________
Question 33:

In C#, which keyword is used to declare an array?

A. array
B. int[]
C. Array
D. var[]
Answer: _________
Question 34:

What is the index of the first element in an array in C#?

A. 1
B. 0
C. -1
D. First
Answer: _________
Question 35:

Which method is used to find the length of an array in C#?

A. Length()
B. Size()
C. Count()
D. Length
Answer: _________
Question 36:

In C#, what is the default value of an uninitialized element in an integer array?

A. -1
B. 0
C. null
D. None of the above
Answer: _________
Question 37:

What is the correct way to access the third element in an array named numbers in C#?

A. numbers[3]
B. numbers(3)
C. numbers(2)
D. numbers[2]
Answer: _________
Question 38:

In C#, which method is used to copy elements from one array to another?

A. Copy()
B. Array.Clone()
C. Clone()
D. Array.Copy()
Answer: _________
Question 39:

What is the correct way to access the length of an array named numbers in C#?

A. numbers.Length
B. Length(numbers)
C. numbers.size()
D. Length(numbers[])
Answer: _________
Question 40:

In C#, which method is used to sort the elements of an array?

A. Sort()
B. Array.Order()
C. Array.Sort()
D. Order()
Answer: _________
Question 41:

What does the Split() method do when applied to a string in C#?

A. Converts the string to lowercase
B. Converts the string to uppercase
C. Splits the string into an array of substrings based on a delimiter
D. Concatenates the string with another string
Answer: _________
Question 42:

In C#, which method is used to convert an array to a string representation?

A. ToString()
B. Convert()
C. Join()
D. Array.ToString()
Answer: _________
Question 43:

What is the correct way to access the last element in an array named numbers in C#?

A. numbers[numbers.Length]
B. numbers[numbers.Length + 1]
C. numbers.Last()
D. numbers[numbers.Length - 1]
Answer: _________
Question 44:

Which method is used to concatenate two or more strings in C#?

A. Concat()
B. Merge()
C. Append()
D. Join()
Answer: _________
Question 45:

In C#, which method is used to find the index of the first occurrence of a specified value in an array?

A. Search()
B. IndexOf()
C. Locate()
D. None of the above
Answer: _________
Question 46:

In C#, what is the correct way to access the length of a string named text?

A. text.Length()
B. text.Size()
C. text.Count()
D. text.Length
Answer: _________
Question 47:

What does the IndexOf() method return if the specified value is not found in an array in C#?

A. 0
B. Null
C. FALSE
D. -1
Answer: _________
Question 48:

What is the purpose of the Reverse() method when applied to an array in C#?

A. Sorts the elements of the array
B. Throws an exception
C. Reverses the order of elements in the array
D. Returns a copy of the array in reverse order
Answer: _________
Question 49:

In C#, what method is used to convert a string to an array of characters?

A. Split()
B. ConvertToArray()
C. ToArray()
D. ToCharArray()
Answer: _________
Question 50:

The Method use to remove white space from a string?

A. Split()
B. Substring()
C. Trim()
D. TrimStart()
Answer: _________
Question 51:

Correct way to find if contents of two strings are equal?

A. if (s1 = s2)
B. if (s1 != s2)
C. if (strcmp (s1 ,s2))
D. if ( s1 is s2)
Answer: _________
Question 52:

Which of these methods can be used to convert all characters in a String into a character array?

A. CharAt()
B. getChars()
C. TocharArray()
D. All of the mentioned
Answer: _________
Question 53:

Which of these methods returns the string such that some characters which are specified to be removed from the end of strings are removed from string by mentioning the number of characters to be removed?

A. Trim()
B. Remove()
C. TrimEnd()
D. Split()
Answer: _________
Question 54:

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

A. Compare()
B. Equals()
C. Assignment '==' operator
D. All of the mentioned
Answer: _________
Question 55:

Select the correct declaration of the defining array of parameters.

A. void func(int[] x) { }
B. void func(int x) { }
C. void func(param int[]) { }
D. void fun(param int[] x) { }
Answer: _________
Question 56:

Which of these methods is used to compare two strings such that after comparison output returns different integer values as (0 for false, 1 for true)?

A. Equals ()
B. == operator
C. Compare()
D. None of the mentioned
Answer: _________
Question 57:

Which of the following statements is correct?

A. replace() replace() method replaces last occurrence of a character in invoking strings with another character
B. replace() method replaces only first occurrence of a character in invoking strings with another character
C. replace() method replaces all occurrences of one character in invoking strings with another character
D. none of the mentioned
Answer: _________
Question 58:

Choose selective differences between an array in c# and array in other programming languages.

A. Declaring array in C# the square bracket([]) comes after the type but not after identifier
B. It is necessary to declare size of an array with its type
C. No difference between declaration of array in c# as well as in other programming languages
D. All of the mentioned
Answer: _________
Question 59:

What is the correct syntax to access the second character of a string named text in C#?

A. text.IndexOf(1)
B. text.SubString(1)
C. text.charAt(1)
D. text[1]
Answer: _________
Question 60:

What is the result of the expression Array.IndexOf(numbers, 5) where numbers = {1, 2, 3, 4, 5} in C#?

A. 5
B. 3
C. 4
D. 2
Answer: _________
Question 61:

In C#, which method is used to split a string into substrings based on a specified delimiter?

A. Separate()
B. Split()
C. Divide()
D. None of the above
Answer: _________
Question 62:

Which of these methods of class String is used to extract all the characters from a String object?

A. CHARAT()
B. Remove()
C. charAt()
D. Replace()
Answer: _________
Question 63:

Which of these base classes are accessible to the derived class members?

A. static
B. protected
C. private
D. Shared
Answer: _________
Question 64:

What is the process by which we can control parts of a program that can access the members of a class?

A. Polymorphism
B. Abstraction
C. Encapsulation
D. Recursion
Answer: _________
Question 65:

Which of these methods of class are used to remove the leading and backward whitespaces?

A. startsWith()
B. trim()
C. Trim()
D. doTrim()
Answer: _________
Question 66:

What is the correct syntax to declare a 2D array with 3 rows and 4 columns in C#?

A. int[][] matrix = new int[3][4]
B. int matrix[3, 4]
C. int[3][4] matrix
D. int[,] matrix = new int[3, 4]
Answer: _________
Question 67:

What is the result of the expression string[] fruits = {"Apple", "Banana", "Orange"}

in C#?

A. A compilation error
B. Initializes an empty array
C. Declares an array with three elements
D. Initializes an array with three elements
Answer: _________
Question 68:

What is the correct way to declare and initialize a string array with three elements in C#?

A. colors = new string[3] {"Red", "Green", "Blue"}
B. string[] colors = {"Red", "Green", "Blue"}
C. string[] colors = new string[] {"Red", "Green", "Blue"}
D. string colors[] = {"Red", "Green", "Blue"}
Answer: _________
Question 69:

What will be the output of the following C# code? static void Main(string[] args)
{
String c = "Hello"

String a

a = c.Replace('l', 'w')

Console.WriteLine(a)

Console.ReadLine()

}

A. Helloll
B. Hewlo
C. Helwo
D. Hewwo
Answer: _________
Question 70:

What will be the output of the following C# code snippet? static void Main(string[] args)
{
String c = "Hello i love you"

String a

a = c.Substring(12, 3)

Console.WriteLine(a)

Console.ReadLine()

}

A. ove
B. you
C. yo
D. love you
Answer: _________
Question 71:

What will be the output of the following C# code? static void Main(string[] args)
{
String obj = "hello"

String obj1 = "world"

String obj2 = obj

Console.WriteLine(obj + " " + obj1)

string s = obj + " " + obj1

Console.WriteLine(s.Length)

Console.ReadLine()

}

A. hello world 10
B. hello world 6
C. hello world 11
D. hello world 5
Answer: _________
Question 72:

What will be the output of the following C# code? static void Main(string[] args)
{
String obj = "hello"

String obj1 = "world"

String obj2 = obj

Console.WriteLine (obj.Equals(obj2) + " " + obj2.CompareTo(obj) )

Console.ReadLine()

}

A. True True
B. False False
C. True 0
D. False 1
Answer: _________
Question 73:

Choose the effective stringBuilder method which helps in producing output for the following C# code? static void Main(string[] args)
{
StringBuilder s = new StringBuilder("object")

s./*______*/("Oriented Language")

Console.WriteLine(s)

Console.ReadLine()

}
Output : objectOriented Language

A. Insert()
B. Add()
C. Append()
D. Join()
Answer: _________
Question 74:

What will be the output of the following C# code? static void Main(string[] args)
{
int[] x = {65, 66, 67, 68, 69, 70}

fun(x)

Console.ReadLine()

}
static void fun(params int[] b )
{
int i

for (i = 5

i > 0

i--)
{
b[i] = b[i] + 32

Console.WriteLine(Convert.ToChar(b[i]))

}
}

A. A, B, C, D, E, F
B. F, E, D, C, B, A
C. f, e, d, c, b
D. b, c, d, e, f
Answer: _________
Question 75:

What will be the output of the following C# code? static void Main(string[] args)
{
String a = "Ilove"

String b = "CSHARP"

b = string.Concat(a,' ',b)

string d = b.TrimStart('I', 'l', 'o', 'H')

Console.WriteLine(d)

Console.ReadLine()

}

A. Ilove CSHARP
B. love CSHARP
C. ve CSHARP
D. ve CSARP
Answer: _________
Question 76:

What will be the output of the following C# code? static void Main(string[] args)
{
double a = 345.09

byte c = (byte) a

Console.WriteLine(c)

Console.ReadLine()

}

A. 98
B. 89
C. 88
D. 84
Answer: _________
Question 77:

What will be the output of the following C# code? class sum
{
public int x

private int y

public void math(int a, int b)
{
x = a * 4

y = b

}
}
class Program
{
static void Main(string[] args)
{
sum p = new sum()

p.math(12, 30)

Console.WriteLine(p.x + " " + p.y)

Console.ReadLine()

}
}

A. 48, 30
B. 48, 0
C. 0, 0
D. Compile time error
Answer: _________
Question 78:

What will be the output of the following C# code? static void Main(string[] args)
{
String obj = "hello"

String obj1 = "worn"

String obj2 = obj

Console.WriteLine(obj + " " + (obj1.Replace('w' ,'c')))

Console.ReadLine()

}

A. hello hello
B. hello worn
C. hello corn
D. hello
Answer: _________
Question 79:

What is the correct way to declare and initialize a jagged array with 2 rows in C#?

A. int[][] jaggedArray = new int[2][]
B. int[,] jaggedArray = new int[2][]
C. int[2][2] jaggedArray = new int[2][]
D. int[][] jaggedArray = new int[2][2]
Answer: _________
Question 80:

What is the correct way to declare and initialize a multidimensional array with 3 rows and 4 columns in C#?

A. int[3, 4] matrix = new int
B. int matrix[3, 4]
C. int[,] matrix = new int[3, 4]
D. int[3][4] matrix
Answer: _________
Question 81:

What will be the output of the following C# code? class math
{
public int a,b

public math(int i, int j)
{
a = i

b = j

}
public void sum(math m)
{
m.a *= 2

m.b += 2

}
}
class Program
{
static void Main(string[] args)
{
math t = new math(20, 10)

t.sum(t)

Console.WriteLine(t.a + " " + t.b)

Console.ReadLine()

}
}

A. 10, 20
B. 20, 10
C. 40, 12
D. 5, 40
Answer: _________
Question 82:

What will be the output of the following C# code? class Program
{
static void Main(string[] args)
{
String c = "i love Csharp"
bool a
a = c.StartsWith("I")
Console.WriteLine(a)
Console.ReadLine()
}
}

A. true
B. false
C. 0
D. 1
Answer: _________
Question 83:

What will be the output of the following C# code? class Program
{
static void Main(string[] args)
{
int i = 5
int j
method1(ref i)
method2(out j)
Console.writeline(i + " " + j)
}
static void method1(ref int x)
{
x = x + x
}
static void method2(out int x)
{
x = 6
x = x * x
}
}

A. 36, 10
B. 10, 36
C. 0, 0
D. 36, 0
Answer: _________
Question 84:

Which is the correct way of defining and initializing an array of 3 integers?

A. int[] a={78, 54}
B. int[] a a = new int[3] a[1] = 78 a[2] = 9 a[3] = 54
C. int[] a a = new int{78, 9, 54}
D. int[] a a = new int[3]{78, 9, 54}
Answer: _________
Question 85:

What will be the output of the following C# code? static void main(string[] args)
{
int n = 1
method(n)
console.Writeline(n)
method1(ref n)
console.Writeline(n)
}
static void method(int num)
{
num += 20
console.writeline(num)
}
static void method1(ref int num)
{
num += 20
console.writeline(num)
}

A. 1 1 1 1
B. 21 1 21 21
C. 11 21 21 11
D. Error
Answer: _________
Question 86:

What will be the output of the following C# code? static void Main(string[] args)
{
String c = "Hello"
String a = c + "Bye"
Console.WriteLine(a)
Console.ReadLine()
}

A. "Hello Bye"
B. "HelloBye"
C. Hello Bye
D. HelloBye
Answer: _________
Question 87:

What will be the output of the following C# code? static void Main(string[] args)
{
char A = 'K'
char B = Convert.ToChar(76)
A++
B++
Console.WriteLine(A+ " " +B)
Console.ReadLine()
}

A. M L
B. U L
C. L M
D. A B
Answer: _________
Question 88:

What is the result of the following code in C#: string[] fruits = {"Apple", "Banana", "Orange"}
Console.WriteLine(fruits[1])

A. Apple
B. Orange
C. Error
D. Banana
Answer: _________
Question 89:

What is the correct way to declare and initialize a jagged array in C#?

A. int[][] jaggedArray = new int[3][]
B. int[][] jaggedArray = new int[][]
C. int[][] jaggedArray = new int[3][3]
D. jaggedArray[][] = new int[3][]
Answer: _________
Question 90:

What is the correct syntax to initialize an array in C#?

A. int numbers[] = {1, 2, 3, 4, 5}
B. int[5] numbers
C. int[] numbers = new int[5]
D. int[5] numbers = {1, 2, 3, 4, 5}
Answer: _________
Question 91:

What is the correct way to declare a string array named colors with three elements in C#?

A. colors[3] = {"Red", "Green", "Blue"}
B. string[] colors = new string[3]
C. string[] colors = {"Red", "Green", "Blue"}
D. colors = new string[] {"Red", "Green", "Blue"}
Answer: _________
Question 92:

What is the result of the expression string[] names = {"John", "Alice", "Bob"}
in C#?

A. A compilation error
B. Declares an array with three elements
C. Initializes an empty array
D. Initializes an array with three elements
Answer: _________
Question 93:

What is the correct way to declare a jagged array in C#?

A. int[][][] jaggedArray
B. int[,] jaggedArray
C. jaggedArray[]
D. int[][] jaggedArray
Answer: _________
Question 94:

What is the correct syntax to declare a multidimensional array in C#?

A. int[2,2] matrix
B. int[,] matrix
C. int[2][2] matrix
D. None of the above
Answer: _________
Question 95:

What will be the output of the following C# code? class Program
{
static void Main(string[] args)
{
String []chars = {"z", "x", "y", "z", "y"}
for (int i = 0
i < chars.Length
++i)
for (int j = i + 1
j < chars.Length
++j)
if(chars[i].CompareTo(chars[j]) == 0)
Console.WriteLine(chars[j])
Console.ReadLine()
}
}

A. zx
B. xy
C. zy
D. yz
Answer: _________
Question 96:

What will be the output of the following C# code? static void Main(string[] args)
{
string s1 = "Hello" + " I " + "Love" + " ComputerScience "
Console.WriteLine(s1)
Console.ReadLine()
}

A. HelloILoveComputerScience
B. Hello I Love ComputerScience
C. Compile time error
D. Hello
Answer: _________
Question 97:

What will be the output of the following C# code? String a = "Csharp"
String b = "CSHARP"
int c
c = a.CompareTo(b)
Console.WriteLine(c)

A. 0
B. 1
C. -2
D. -1
Answer: _________
Question 98:

Complete the following C# code with "foreach condition". int[][]a = new int[2][]
a[0] = new int[3]{3, 4, 2}
a[1] = new int[2]{8, 5}
foreach( int[]i in a)
{
/* add for loop */
console.write( j+ " ")
console.writeline()
}

A. foreach (int j = 1 (j(<)(a(0).GetUpperBound)) (j++))
B. foreach (int j = 1 (j(<)(a.GetUpperBound(0))) (j++))
C. foreach (int j in a.Length)
D. foreach (int j in i)
Answer: _________
Question 99:

What will be the output of the following C# code? static void Main(string[] args)
{
Program p = new Program()
p.display(2, 3, 8)
int []a = { 2, 56, 78, 66 }
Console.WriteLine("example of array")
Console.WriteLine("elements added are")
p.display(a)
Console.ReadLine()
}
public void display(params int[] b)
{
foreach (int i in b)
{
Console.WriteLine("ARRAY IS HAVING:{0}", i)
}
}

A. Compile time error
B. Run time error
C. Code runs successfully but prints nothing
D. Code runs successfully and prints given on console
Answer: _________
Question 100:

What will be the output of the following C# code? static void main(string[] args)
{
int []arr = new int[]{ 1, 2, 3, 4, 5}
fun (ref arr)
for (int i = 0
i < arr.Length
i++)
Console.WriteLine( arr[i] + " ")
}
static void fun(ref int[]a)
{
a = new int[6]
a[3] = 32
a[1] = 24
}

A. 0, 0, 32, 0, 0, 0
B. 0, 24, 0, 32, 0, 0
C. 24, 0, 32, 0, 0, 0
D. None of the above
Answer: _________
Question 101:

What will be the output of the following C# code? static void Main(string[] args)
{
string s1 = " Cshr "
string s2 = s1.Insert(3 , " a ")
string s3 = s2.Insert(5 , " p ")
for (int i = 0
i < s3.Length
i++)
Console.WriteLine(s3[i])
Console.ReadLine()
}

A. Cshar
B. CsharP
C. Csharp
D. Cshrap
Answer: _________
Question 102:

What will be the output of the following C# code? static void Main(string[] args)
{
string s1 = "Hello I Love Csharp "
Console.WriteLine(Convert.ToChar( (s1.IndexOf('I') - s1.IndexOf('l')) * s1.IndexOf('p'))
Console.ReadLine()
}

A. I
B. Hello I
C. Love
D. H
Answer: _________
Question 103:

Which among the following is the correct way to find out the index of 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" int i i = a.SecondIndexOf("s")
B. String a = "She sold her beauty in one night to someone else" int i, j i = a.FirstIndexOf("s") j = a.IndexOf("s", i + 1)
C. String a = "She sold her beauty in one night to someone else" int i, j i = a.IndexOf("s") j = a.IndexOf("s", i + 1)
D. None of the mentioned
Answer: _________
Question 104:

What will be the output of the following C# code? static void Main(string[] args)
{
string s1 = "Hello"
string s2 = "hello"
if (s1 == s2)
Console.WriteLine("Equal")
else
Console.WriteLine("Unequal")
if (s1.Equals (s2))
Console.WriteLine("Equal")
else
Console.WriteLine("Unequal")
Console.ReadLine()
}

A. Equal Unequal
B. Unequal Equal
C. Equal Equal
D. Unequal Unequal
Answer: _________
Question 105:

What will be the output of the following C# code snippet? static void main(String args[])
{
char chars[] = {'x', 'y', 'z'}
String s = new String(chars)
Console.WriteLine(s)
}

A. x
B. xy
C. z
D. xyz
Answer: _________
Question 106:

What is the correct way to declare a string array in C#?

A. string[] colors
B. array colors
C. string colors[]
D. colors[] = string
Answer: _________
Question 107:

How do you access the first element of an array named 'numbers' in C#?

A. first(numbers)
B. numbers.first
C. numbers(1)
D. numbers[0]
Answer: _________
Question 108:

What is the correct way to initialize an array of integers with values {1, 2, 3} in C#?

A. int[] numbers = new int[] {1, 2, 3}
B. int numbers[] = {1, 2, 3}
C. int[] numbers = {1, 2, 3}
D. numbers[] = {1, 2, 3}
Answer: _________
Question 109:

How do you find the number of elements in an array named 'values' in C#?

A. Length(values)
B. values.Count
C. values.Length
D. values.Size
Answer: _________
Question 110:

What is the correct syntax to declare and initialize a 2D array in C# with dimensions 3x3?

A. int[3,3] matrix
B. int[3][3] matrix
C. int matrix[][] = new int[3][3]
D. int[,] matrix = new int[3,3]
Answer: _________
Question 111:

What is the correct way to declare an array of strings with 5 elements in C#?

A. string[5] names
B. string[5] names = new string[]
C. string[] names = new string[5]
D. names[] = new string[5]
Answer: _________
Question 112:

How do you access the last element of an array named 'values' in C#?

A. values[length(values)]
B. values[values.Length - 1]
C. Last(values)
D. None of the above
Answer: _________
Question 113:

What will be the output of the following C# code? static void Main(string[] args)
{
int [] a = {1, 2, 3, 4, 5}
fun(a)
Console.ReadLine()
}
static void fun(params int[] b )
{
int[] k = { 3, 4, 7, 8,'x00' }
for (int i = 0
i < b.Length
i++)
{
b[i] = b[i] + k[i]
Console.WriteLine( b[i] + " ")
}
}

A. Compile time error
B. 3, 4, 7, 8, 5
C. 3, 4, 7, 8, 5, 1, 2, 3, 4, 5
D. 4, 6, 10, 12, 5
Answer: _________
Question 114:

Which statement is correct about following c#.NET code? int[] a= {11, 3, 5, 9, 6}

A. 'a' is a reference to the array created on stack
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 'System.Array' class
D. None of the mentioned
Answer: _________
Question 115:

What will be the output of the following C# code? static void Main(string[] args)
{
int[] a = { 2, 21, 34, 46, 85, 88, 90}
fun(a)
Console.WriteLine(a + " ")
Console.ReadLine()
}
static void fun(params int [] b )
{
int [] c = { 1, 2, 3, 4, 5, 6, 7}
int i
for (i = 0
i < b.Length
i++)
if (b[i] % 2 == 0)
{
c[i] = b[i]
}
Console.WriteLine("even numbers are:")
for (i = 0
i <= b.Length
i++)
{
Console.WriteLine(c[i])
}
}

A. Compile time error
B. 2, 21, 34, 4, 6, 46, 88, 90
C. 2, 4, 34, 46, 6, 88, 90
D. 2, 34, 46, 88, 90
Answer: _________
Question 116:

How to print on the screen?

A. Console.WriteLine("\")
B. Console.WriteLine("\") "
C. Console.WriteLine("\\")
D. Console.WriteLine("\\\")
Answer: _________
Question 117:

What will be the output of the following C# code? static void Main(string[] args)
{
int a = 5
int b = 0, c = 0
method (a, ref b, ref c)
Console.WriteLine(b + " " + c)
Console.ReadLine()
}
static int method(int x, int p, ref int k)
{
p = x + x * x
k = x * x + p
return 0
}

A. 30, 55
B. 55, 30
C. Compile time error
D. 0, 0
Answer: _________
Question 118:

What will be the output of the following C# code? static void Main(string[] args)
{
String a = "Ilove"
String b = "CSHARP"
b = string.Concat(a, ' ', b)
Console.WriteLine(b)
Console.ReadLine()
}

A. IloveCSHARP
B. I loveCSHARP
C. Ilove
D. Ilove CSHARP
Answer: _________
Question 119:

What will be the output of the following C# code? static void Main(string[] args)
{
String obj = "hello"
String obj1 = "world"
String obj2 = obj
string s = obj+" "+obj1
Console.WriteLine(s.IndexOf('r'))
Console.ReadLine()
}

A. 7
B. 8
C. 9
D. 10
Answer: _________
Question 120:

What will be the output of the following C# code? static void main(string[] args)
{
int i
int res = fun (out i)
console.writeline(res)
console.readline()
}
static int fun(out int i)
{
int s = 1
i = 7
for (int j = 1
j <= i
j++ )
s = s * j
return s
}

A. 4490
B. 5040
C. 5400
D. 3500
Answer: _________
Question 121:

What will be the output of the following C# code? static void Main(string[] args)
{
String obj = "hello"
String obj1 = "world"
String obj2 = obj
string s = obj + " " + obj1
Console.WriteLine(s.Substring(6 ,5))
Console.ReadLine()
}

A. hello
B. orld
C. world
D. o world
Answer: _________
Question 122:

What will be the output of the following C# code? static void Main(string[] args)
{
int i, j
int[, ] arr = new int[ 3, 3]
for (i = 0
i < 3
++i)
{
for (j = 0
j < 3
++j)
{
arr[i, j] = i * 2 + i * 2
Console.WriteLine(arr[i, j])
}
Console.ReadLine()
}
}

A. 0, 0, 0 4, 4, 4 8, 8, 8
B. 4, 4, 4 8, 8, 8 12, 12, 12
C. 8, 8, 8 12, 12, 12 16, 16, 16
D. 0, 0, 0 1, 1, 1 2, 2, 2
Answer: _________
Question 123:

What will be the output of the following C# code? static void Main(string[] args)
{
object[] a = {" 1 ", 4.0f, " harsh "}
fun(a)
Console.ReadLine()
}
static void fun(params object[] b)
{
for (int i = 0
i < b.Length - 1
i++)
Console.WriteLine(b[i] + " ")
}

A. 1 4.0 harsh
B. 1 4
C. 1 4 hars
D. 1 4 harsh
Answer: _________
Question 124:

What will be the output of the following C# code? class sum
{
public int x
public int y
public int add (int a, int b)
{
x = a + b
y = x + b
return 0
}
}
class Program
{
static void Main(string[] args)
{
sum obj1 = new sum()
sum obj2 = new sum()
int a = 2
obj1.add(a, a + 1)
obj2.add(5, a)
Console.WriteLine(obj1.x + " " + obj2.y)
Console.ReadLine()
}
}

A. 6, 9
B. 5, 9
C. 9, 10
D. 3, 2
Answer: _________
Question 125:

What will be the output of the following C# code? static void Main(string[] args)
{
String c = " Hello Computer "
String a = c.Trim()
Console.WriteLine(""" + s + """)
}

A. " Hello Computer "
B. "HelloComputer"
C. "Hello Computer"
D. Hello Computer
Answer: _________
Question 126:

Select the correct match of parameter declaration. static Void main(string[] args)
{
int a = 5
int b = 6
float c = 7.2f
math (ref a, ref b, ref c)
Console.WriteLine(a + " " + b + " " + c)
}
static int math(/*add parameter declaration */)
{
a += b
b *= (int)c
c += a * b
return 0
}

A. ref int a, int b, ref float c
B. ref int a, ref float c, ref int b
C. ref int a, ref int b, float c
D. ref int a, ref int b, ref float c
Answer: _________
Question 127:

What will be the output of the following C# code? static void Main(string[] args)
{
int[] x = { 80, 82, 65, 72, 83, 67 }
fun(x)
Console.ReadLine()
}
static void fun(params int [] b )
{
int i
for (i = 5
i >=0
i--)
{
Console.WriteLine(Convert.ToChar(b[i]))
}
}

A. 67 83 72 65 82 80
B. P R A H S C
C. C S H A R P
D. 80 82 65 72 83 67
Answer: _________
Question 128:

What will be the output of the following C# code snippet? static void Main(string[] args)
{
string c = "hello"
string c1 = c.Remove(1)
Console.WriteLine(c1)
Console.ReadLine()
}

A. ello
B. h
C. hell
D. none of the mentioned
Answer: _________
Question 129:

Which method does following C# code explains? static void Main(string[] args)
{
int a = 10, b = 20
method(ref a, ref b)
console.writeline(a + " " + b)
}
static void swap(ref int i, ref int j)
{
int t
t = i
i = j
j = t
}

A. Call by reference
B. Call by value
C. Output parameter
D. parameter arrays
Answer: _________
Question 130:

What will be the output of the following C# code? static void Main(string[] args)
{
int [] a = {1, 2, 3, 4, 5}
fun(a)
Console.ReadLine()
}
static void fun(params int[] b )
{
for (int i = 0
i < b.Length
i++)
{
b[i] = b[i] * 5
Console.WriteLine(b[i] + "")
}
}

A. 1, 2, 3, 4, 5
B. 5, 10, 15, 20, 25
C. 5, 25, 125, 625, 3125
D. 6, 12, 18, 24, 30
Answer: _________
Question 131:

Which statement is correct about following C# code? int[, ]a={{5, 4, 3},{9, 2, 6}}

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
D. a.GetUpperBound(0) gives 2
Answer: _________
Question 132:

What will be the output of the following C# code? class Program
{
static void Main(string[] args)
{
String s1 = "I love You"
String s2 = s1
Console.WriteLine((s1 == s2) + " " + s1.Equals(s2))
Console.ReadLine()
}
}

A. true true
B. false false
C. true false
D. false true
Answer: _________
Question 133:

What will be the output of the following C# code? static void Main(string[] args)
{
string s = " i love you"
Console.WriteLine(s.IndexOf('l') + " " + s.lastIndexOf('o') + " " + s.IndexOf('e'))
Console.ReadLine()
}

A. 3 5 7
B. 4 5 6
C. 3 9 6
D. 2 4 6
Answer: _________

Answer Key

1: A
2: D
3: C
4: C
5: B
6: A
7: D
8: D
9: D
10: A
11: C
12: B
13: B
14: D
15: A
16: C
17: B
18: D
19: B
20: A
21: C
22: A
23: A
24: C
25: A
26: C
27: A
28: B
29: B, F
30: C
31: B
32: D
33: B
34: B
35: D
36: B
37: D
38: D
39: A
40: C
41: C
42: C
43: D
44: A
45: B
46: D
47: D
48: C
49: D
50: C
51: C
52: C
53: A
54: D
55: D
56: C
57: C
58: A
59: D
60: C
61: B
62: B
63: B
64: C
65: C
66: D
67: C
68: C
69: D
70: C
71: C
72: C
73: C
74: C
75: C
76: B
77: D
78: C
79: A
80: C
81: C
82: B
83: B
84: D
85: B
86: D
87: C
88: D
89: A
90: C
91: C
92: B
93: D
94: B
95: C
96: B
97: D
98: D
99: D
100: B
101: C
102: D
103: C
104: D
105: D
106: A
107: D
108: C
109: C
110: D
111: C
112: B
113: D
114: C
115: D
116: C
117: C
118: D
119: B
120: B
121: C
122: A
123: D
124: B
125: C
126: D
127: C
128: B
129: A
130: B
131: C
132: A
133: C