Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
#1 - string str = "ABCDVER" + "1";
#2 - string str2 = "ABCDVER"; string str3 = "1";
#3 - string str1 = string.format("{0}{1}",str2,str3);

Line#1 and Line#2 gives same answer?. Please confirm.

Thanks
Arun

What I have tried:

#1 - string str = "ABCDVER" + "1";
#2 - string str2 = "ABCDVER"; string str3 = "1";
#3 - string str1 = string.format("{0}{1}",str2,str3);

Line#1 and Line#2 gives same answer?. Please confirm.

Thanks
Arun
Posted
Updated 17-Sep-16 1:50am
Comments
Philippe Mori 17-Sep-16 8:30am    
Don't repeat your question twice.
Philippe Mori 17-Sep-16 8:34am    
Try it. There are no value in asking such question! And if you are in an interview or an exam, don't ask question with your phone!
Patrice T 17-Sep-16 9:39am    
There is an easy way to know, provided you have a compiler handy.

No.
Lines 1 and 3 give the same answer in that str and str1 are the same - but not 1 and 2.

You could have solved this very easily with the debugger, or even just by writing code:

C#
string str = "ABCDVER" + "1";
string str2 = "ABCDVER"; string str3 = "1";
string str1 = string.Format("{0}{1}", str2, str3);
if (str == str1) Console.WriteLine("Yes");
else Console.WriteLine("No");
 
Share this answer
 
see visually

C#
class Program
{ 
    static void Main(string[] args)
    {
    string str = "ABCDVER" + "1";
    string str2 = "ABCDVER"; string str3 = "1";
    string str1 = string.Format("{0}{1}",str2,str3);
    System.Console.WriteLine(str);
    System.Console.WriteLine(str1);
    System.Console.WriteLine("is equal?: " +  (str1 == str));
    System.Console.ReadLine(); 
    } 
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900