AmbitionBox
Discover Best Places to work in India
Discover best places to work
Compare & find best workplace
Bring your workplace to life
Highlight your company's perks
Read reviews for 6L+ companies
Rate your former or current company
Discover salaries for 8L+ companies
Calculate your take home salary
Check your market value
Help other jobseekers
Read interviews for 90K+ companies
Interviews questions for 1K+ colleges
Contribute your interview questions
C# Programming
Which of the following string() method are used to compare two strings with each other?
CopyTo()
Copy()
Compare()
CompareTo()
Creates a new string by copying one string to another.
Which of the following statement is correct about a string in C#.NET?
The System.Array class is used to represent a string
A string has a zero-based index
A number cannot be represented in the form of a string
A string is mutable because it can be modified once it has been created
Answer: Option (B)
Choose Output for the following set of code :
staticvoid Main(string[] args)
{
string s1 ="Hello"+" I "+"Love"+" ComputerScience ";
Console.WriteLine(s1);
Console.ReadLine();
}
HelloILoveComputerScience
Hello I Love ComputerScience
Compile time error
Hello
Here ‘+’ defined operator works as concatenation for strings. Output : Hello I Love ComputerScience.
Which of the following statements are correct?
String is value type
String literals can contain any character literal including escape sequences
The equality operators are defined to compare values of string objects as well as references
All of the mentioned
Which of these operators can be used to concatenate two or more String objects?
+
+=
&
||
string s1 = “Hello”+ ” I ” + “Love” + ” ComputerScience “; Console.WriteLine(s1); Hello I Love ComputerScience.
The Method use to remove white space from string?
Split()
Substring()
Trim()
TrimStart()
Perfectly removes a whitespace from string whereas TrimStart() removes a string of characters from the end of the string.
What is output for the following set of code:
string s1 =" Cshr ";
string s2 = s1.Insert(3 , " a ");
string s3 = s2.Insert(5 , " p ");
for(int i =0;i < s3.Length; i++)
Console.WriteLine(s3[i]);
Cshar
CsharP
Csharp
Cshrap
Insertion of character ‘a’ at postion ‘3’ using insert() which returns a new string with a substring inserted at a specified location. Output: Csharp
What is output for the following set of code?
string s1 ="Hello";
string s2 ="hello";
if(s1 == s2)
Console.WriteLine("Equal");
else
Console.WriteLine("Unequal");
if(s1.Equals(s2))
Equal Unequal
Unequal Equal
Equal Equal
Unequal Unequal
In first comparison it is being checked either two strings are equal or not but in second comparison it is checked whether two references are equal or not. Output: Unequal Unequal
Correct way to find if contents of two strings are equal ?
if (s1 = s2)
if (s1 == s2)
if (strcmp (s1 ,s2))
if ( s1 is s2)
“==” operator used to compare length of two strings and strcmp() is the inbuilt method derived from string class.
Join India’s largest community to research company culture
Are you a student or working professional?
Student/Never worked
I am a student/I have never worked
Working Professional
I am working/I have worked before
What are your preferred job locations?
Popular Cities
Other Cities
Follow your preferred designations/job profiles
Suggestions based on your job profile
vs
Similar Companies