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);
}
- Virus
- Virus Covid
- Virus Covid-19
- Runtime Exception
Correct answer: 2
Virus Covid
The above code will print "Virus Covid" on the console screen.
2) There are following statements are given below, which of them are correct about "String" in C#.NET?
- The memory space allocated to a string in the stack segment.
- The memory space allocated to a string in the heap segment.
- A String is a built-in enumeration.
- The memory space allocation to a string depends on string size.
Correct answer: 2
The memory space allocated to a string in the heap segment.
In the above statements, only the second statement is correct about "Sstring" in C#.NET.
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]);
}
- CoronaVirus Covid-19
- CoronaVirusCovid-19
- Array of strings cannot be created
- Runtime Exception
Correct answer: 1
CoronaVirus Covid-19
The above code will print "CoronaVirus Covid-19" on console screen.
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 + " ");
}
}
- 1720-plague 1820-CHOLERA 1920-SpanishFlue 2020-CoronaVirus
- 1720-plague:1820-CHOLERA:1920-SpanishFlue:2020-CoronaVirus
- Spilt() method does not exist
- Runtime Exception
Correct answer: 1
1720-plague 1820-CHOLERA 1920-SpanishFlue 2020-CoronaVirus
The above code will print "1720-plague 1820-CHOLERA 1920-SpanishFlue 2020-CoronaVirus" on console screen.
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);
}
- My lucky number: '108'
- My lucky number: 108
- Runtime Exception
- Syntax Error
Correct answer: 2
My lucky number: 108
The above code will print "My lucky number: 108" on console screen.