logo

CuriousTab

CuriousTab

Discussion


Home C# Programming Strings See What Others Are Saying!
  • Question
  • Which of the following statements will correctly copy the contents of one string into another?


  • Options
  • A.
    String s1 = "String";
    String s2; 
    s2 = s1;
  • B.
    String s1 = "String" ; 
    String s2;
    s2 = String.Concat(s1, s2);
  • C.
    String s1 = "String"; 
    String s2;
    s2 = String.Copy(s1);
  • D.
    String s1 = "String"; 
    String s2;
    s2 = s1.Replace();
  • E.
    String s1 = "String"; 
    String s2;
    s2 = s2.StringCopy(s1);

  • Correct Answer
  • String s1 = "String"; 
    String s2;
    s2 = String.Copy(s1);
     


  • More questions

    • 1. Which of the following statements is correct?

    • Options
    • A. Static methods can be a virtual method.
    • B. Abstract methods can be a virtual method.
    • C. It is necessary to override a virtual method.
    • D. When overriding a method, the names and type signatures of the override method must be the same as the virtual method that is being overriden.
    • E. We can override virtual as well as non-virtual methods.
    • Discuss
    • 2. In a HashTable Key cannot be null, but Value can be.

    • Options
    • A. True
    • B. False
    • Discuss
    • 3. An Employee class has a property called age and emp is reference to a Employee object and we want the statement Console.WriteLine(emp.age) to fail. Which of the following options will ensure this functionality?

    • Options
    • A. Declare age property with only get accessor.
    • B. Declare age property with only set accessor.
    • C. Declare age property with both get and set accessors.
    • D. Declare age property with get, set and normal accessors.
    • E. None of the above
    • Discuss
    • 4. Exceptions can be thrown even from a constructor, whereas error codes cannot be returned from a constructor.

    • Options
    • A. True
    • B. False
    • Discuss
    • 5. An object of a derived class cannot access private members of base class.

    • Options
    • A. True
    • B. False
    • Discuss
    • 6. Which of the following statements are correct about delegates?

    • Options
    • A. Delegates cannot be used to call a static method of a class.
    • B. Delegates cannot be used to call procedures that receive variable number of arguments.
    • C. If signatures of two methods are same they can be called through the same delegate object.
    • D. Delegates cannot be used to call an instance function. Delegates cannot be used to call an instance subroutine.
    • Discuss
    • 7. Which of the following statements are correct about constructors in C#.NET?

      1. Constructors cannot be overloaded.
      2. Constructors always have the name same as the name of the class.
      3. Constructors are never called explicitly.
      4. Constructors never return any value.
      5. Constructors allocate space for the object in memory.

    • Options
    • A. 1, 3, 5
    • B. 2, 3, 4
    • C. 3, 5
    • D. 4, 5
    • E. None of these
    • Discuss
    • 8. Which of the following statements is incorrect about a delegate?

    • Options
    • A. A single delegate can invoke more than one method.
    • B. Delegates can be shared.
    • C. Delegate is a value type.
    • D. Delegates are type-safe wrappers for function pointers.
    • E. The signature of a delegate must match the signature of the method that is to be called using it.
    • Discuss
    • 9. What will be the output of the C#.NET code snippet given below?

      namespace CuriousTabConsoleApplication
      {
          class Sample
          { 
              public static void fun1()
              { 
                  Console.WriteLine("CuriousTab1 method");
              }
              public void fun2()
              { 
                  fun1(); 
                  Console.WriteLine("CuriousTab2 method");
              }
              public void fun2(int i)
              { 
                  Console.WriteLine(i);
                  fun2(); 
              } 
          } 
          class MyProgram
          { 
              static void Main(string[ ] args)
              { 
                  Sample s = new Sample(); 
                  Sample.fun1(); 
                  s.fun2(123);
              } 
          } 
      }

    • Options
    • A.
      Tab1 method 
      123
      Tabl method 
      Tab2 method
    • B.
      Tab1 method 
      123
      Tab2 method
    • C.
      Tab2 method 
      123
      Tab2 method 
      Tabl method
    • D.
      Tabl method
      123
    • E.
      Tab2 method 
      123
      Tabl method
    • Discuss
    • 10. Which of the following is the correct way to implement a write only property Length in a Sample class?

    • Options
    • A.
      class Sample
      {
          public int Length
          {
              set
              {
                  Length = value;
              } 
          } 
      }
    • B.
      class Sample
      {
          int len;
          public int Length
          {
              get
              {
                  return len;
              }
              set
              {
                  len = value;
              } 
          } 
      }
    • C.
      class Sample
      {
          int len;
          public int Length
          {
              WriteOnly set
              {
                  len = value;
              } 
          } 
      }
    • D.
      class Sample
      {
          int len;
          public int Length
          {
              set
              {
                  len = value;
              }
          } 
      }
    • Discuss


    Comments

    There are no comments.

Enter a new Comment