Home » Aptitude Questions and Answers » C# Aptitude Questions and Answers

C# Strings Aptitude Questions and Answers | Set 5

C# Strings Aptitude Questions | Set 5: This section contains aptitude questions and answers on C# Strings.
Submitted by Nidhi, on April 05, 2020

1) What is the correct output of given code snippets?
static void Main(string[] args)
{
	String str = "CoronaVirus Covid-19";
	String sub;

	sub = str.Substring(6, 11);

	Console.WriteLine(sub);
}
  1. Virus
  2. Virus Covid
  3. Virus Covid-19
  4. Runtime Exception

2) There are following statements are given below, which of them are correct about "String" in C#.NET?
  1. The memory space allocated to a string in the stack segment.
  2. The memory space allocated to a string in the heap segment.
  3. A String is a built-in enumeration.
  4. The memory space allocation to a string depends on string size.

3) What is the correct output of given code snippets?
static void Main(string[] args)
{
    String []str = {"CoronaVirus", "Covid-19"};
    Console.WriteLine(str[0]+ " "+str[1]);
}
  1. CoronaVirus Covid-19
  2. CoronaVirusCovid-19
  3. Array of strings cannot be created
  4. Runtime Exception

4) What is the correct output of given code snippets?
static void Main(string[] args)
{
    String str = "1720-plague:1820-CHOLERA:1920-SpanishFlue:2020-CoronaVirus";
    String []sub;

    sub = str.Split(':');

    foreach (string s in sub)
    {
        Console.Write(s + " ");
    } 
}
  1. 1720-plague 1820-CHOLERA 1920-SpanishFlue 2020-CoronaVirus
  2. 1720-plague:1820-CHOLERA:1920-SpanishFlue:2020-CoronaVirus
  3. Spilt() method does not exist
  4. Runtime Exception

5) What is the correct output of given code snippets?
static void Main(string[] args)
{
	int num = 108;
	String s1 = "My lucky number: ";
	String s2 = Convert.ToString(num);

	Console.WriteLine("{0}{1}", s1, s2);
}
  1. My lucky number: '108'
  2. My lucky number: 108
  3. Runtime Exception
  4. Syntax Error






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.