Select chapter



Basics (2.papers)
Data Types (2.papers)
enums (2.papers)
OOPS (4.papers)
Arrays (1.papers)
Structs (2.papers)
Properties (2.papers)
Strings (2.papers)
Interfaces (1.papers)
Constructors (2.papers)
Ref-Out-Keywords (1.papers)
Collections (2.papers)
Generics (1.papers)
Hide

Sponsored Links


  

c# strings interview questions and answers

1
What is the difference between StringBuilder and String in C# ?
  1. StringBuilder is immutable where as String is mutable.
  2. Objects of type StringBuilder are mutable where as objects of type System.String are immutable. 
  3. String is more efficient than the StringBuilder for string manipulation.
  4. All the above
Show Answer
Share Facebook gmail Twitter
2
What is the difference between string  and String in C# ?
  1. Both are same and string keyword is an alias for String class.
  2. string is a primitive type defined in C# language and is converted into String during compilation.
  3. string is mutable and String is immutable.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
3
What is Immutability of a string ?
  1. Content of a string cannot be changed after assigning data to the string.
  2. string content can be changed without creating a new string.
  3. strings are stored in heap memory.
  4. strings are stored in stack memory.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
6
What is a verbatim string ?
  1. A verbatim string is a string which is having @ [ at ] character before starting of double quotation while declaring a string.
  2. A verbatim string is mutable string.
  3. A verbatim string is having dollar ( $ ) before starting a string.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
7
How  to create an empty string in C# ?
  1. string s= String.Empty();
  2. string s=null;
  3. string s=String.Empty;
  4. string s=string.Empty(" ");
Show Answer
Share Facebook gmail Twitter
8
How to find Index of a string or a character in C# ?
  1. Use IndexOf method.
  2. Use GetIndex Method.
  3. Use Index property.
  4. Use Index method.
Show Answer
Share Facebook gmail Twitter
9
How to split a string in C# ?
  1. use Split method.
  2. use IndexOf method.
  3. use SubString method.
  4. use Trim method.
Show Answer
Share Facebook gmail Twitter
10
What is a string in C# ?
  1. string is a character array in C#.
  2. string is immutable in C#.
  3. string is a reference type in C#.
  4. All the above definitions are valid.
Show Answer
Share Facebook gmail Twitter
11
Which of the following statement is correct about a String in C#.NET?
  1. string is not an index based array.
  2. string is a 0-index based character array.
  3. string is a 1-index based character array.
  4. strings are constants.
Show Answer
Share Facebook gmail Twitter
12
How to compare two string for data equality ( assuming two strings are given with the names S and SS ) ?
1. S.CompareTo(SS);
2. String.Compare(S,SS);
3. If(S==SS)
4. Object.Equals(S,SS);
5. S.Equals(S,SS);
  1. Options 1, 2 & 3 are correct way to compare two strings for data equality.
  2. Options 2,3 & 5 Only correct.
  3. Options 2,4&5 Only Only correct.
  4. All the 5 options can be used for checking 2 strings data equality.
Show Answer
Share Facebook gmail Twitter
13
What is the use of C# substring?
  1. Substring is used for getting a portion of a string present in the source string.
  2. Substring used for extracting a portion of a string from a given position.
  3. Using substring we can extract a string from a predefined start position to predefined end position.
  4. All the above options are correct.
Show Answer
Share Facebook gmail Twitter
14
How to get ascii value of a char or a string in C# ?
  1. char c= 'y'; 
    int i = c; 
  2. string s="skill";
    byte[] asciiBytes = Encoding.ASCII.GetBytes(s);
  3. string s= "skill";
    int i =(int ) s;
  4. First option is correct for getting ascii value of char and second option is correct for getting ascii values of all characters present in a string.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
16
Which of the below given code segments is used for displaying  output as  G:\Skillgun\questions\Aptitude\error.txt ?
  1. string s=@"G:\Skillgun\questions\Aptitude\error.txt"; Console.WriteLine(s);
  2. string s="G:\\Skillgun\\questions\\Aptitude\\error.txt";   Console.WriteLine(s);
  3. 1,2
  4. string s="G:\Skillgun\questions\Aptitude\error.txt"; Console.WriteLine(s);
Show Answer
Share Facebook gmail Twitter
17
Which of the following is a verbatim string ?
  1. string s=@"erd";
  2. string s="@rghjk";
  3. string s=#"yhgff";
  4. None of the above
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
19
How to determine whether a String contains a numeric value ?
  1. string.Contains();
  2. We can not find with built-in method.
  3. TryParse();
  4. string.Match()
Show Answer
Share Facebook gmail Twitter
20
How to replace a character with another character in a string ( choose the best way of doing it ) ?
  1. Use replace method.
  2. Use remove method and then use insert method.
  3. Use substring method.
  4. None of the above.
Show Answer
Share Facebook gmail Twitter
Read more papers :