Vidyalelo
C# Programming · all questions

Arrays and Strings in C Sharp
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

134

Questions

5/7

Page

Pick an option on a question to see the right answer and solution.

Select the correct declaration of the defining array of parameters.

Options are not available for this question.

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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)?

Select an option to see the answer and solution.

Which of the following statements is correct?

Select an option to see the answer and solution.

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]));
    }
}

Select an option to see the answer and solution.

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();
}

Select an option to see the answer and solution.

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();
}

Select an option to see the answer and solution.

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();
    }
}

Select an option to see the answer and solution.

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();
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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();
    }
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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();
}

Select an option to see the answer and solution.

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);

Select an option to see the answer and solution.

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();
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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);
    }
}

Select an option to see the answer and solution.

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

Select an option to see the answer and solution.

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;
}

Select an option to see the answer and solution.