Search Placementyogi.com
 

C# Strings - Advanced Objective Questions

1

What is the output of the following C# program?

using System;
namespace PlacementYogi
{
    class Strings
    {
        public static void Main(String[] args) 
        {
            String str1 = "THAT_DOG_COLOUR_IS_BROWN";
            String str2 = "";
            int i, j;
            i = str1.IndexOf("O");
            j = str1.IndexOf("O", i + 1);
            str2 = str1.Substring(j);
            Console.WriteLine(str2);
        }
    }
}
A.

OG_COLOUR_IS_BROWN

B.

OLOUR_IS_BROWN

C.

OUR_IS_BROWN

D.

OWN

E.

None of the above

See Answer & Explanation Lets Discuss
Correct answer is : B
Explanation

i = str1.IndexOf("O") gets the index of first occurrence of O

j = str1.IndexOf("O", i + 1) starts searching from G (i + 1) and gets the index of second occurrence of O.

So str2 = str1.Substring(j) gives the substring starting from j till end because there is no length specified.

 
2

What is the output of the following C# program?

using System;
namespace PlacementYogi
{
    class Strings
    {
        public static void Main(String[] args)
        {
            string str = "Hi C#";
            Console.WriteLine( String.Compare(str,"Hi C-Sharp").GetType()); 
        }
    }
}
A.

1

B.

False

C.

System.Int32

D.

None of the above

See Answer & Explanation Lets Discuss
Correct answer is : C
Explanation

String.Compare(string strA, string strB) returns 0 if both strings are same otherwise 1. In the given code both strings are not same so 1 is returned and GetType() gets the type of 1 which is an integer (System.Int32).

 
3

What is the output of the following C# program?

using System;
namespace PlacementYogi
{
    class Strings
    {
        public static void Main(String[] args)
        {
            string str1 = "456.123";
            double double1 = Convert.ToDouble(str1);
            double double2 = double.Parse(str1);
            Console.Write(double1 +" "+ double2);
        }
    }
}
A.

456.123 456.123

B.

456 456

C.

456.123 456

D.

456 456.123

E.

456.0 456.0

See Answer & Explanation Lets Discuss
Correct answer is : A
Explanation

Convert.ToDouble(string value) : Converts string representation of a number("456.123") to the equivalent double (456.123)

double.Parse(string value) : Converts string representation of a number("456.123") to the equivalent double (456.123)

 
 

Banner to LogicGuns.com

Hide Page Information

C# Strings - Advanced Objective Questions and Answers with Explanation

Here you can find advanced level C# strings interview questions with answers and explanation.

Why Strings in C#?

In this section you can learn and practice different types of advanced level questions with answers on strings to improve your skills in order to face the interviews, competitive examinations and various entrance tests (CAT, GATE, GRE, MAT, Bank Exam etc.) with full confidence.

Where can I get C# Strings Advanced Questions and Answers with Explanation?

PlacementYogi provides you lots of fully solved advanced level strings questions and answers with explanation. Fully solved examples with detailed answer description, explanation are given and it would be easy to understand. All students, freshers can download Operators quiz questions with answers as PDF files and eBooks.

Where can I get Advanced Level C# Strings Interview Questions and Answers (objective type, multiple choice)?

Here you can find objective type advanced strings questions and answers for interview and entrance examination. Multiple choice and TRUE or FALSE type and YES or NO type questions are also provided.