Concatenates two specified instances of String and returns the new string that contains both the concatenated strings.
For example:
string strOne = "Osama";
string strTwo = "Maverick";
MessageBox.Show(string.Concat(strOne,strTwo));
Output:
OsamaMaverick
If you write this:
MessageBox.Show(strOne + strTwo);
Then Output would be the same:
Output:
OsamaMaverick
Another example:
string strOne = "1";
string strTwo = "2";
MessageBox.Show(strOne + strTwo);
Output:
12 (because it concatenates and cant add them together)
If you write this:
string strOne = "1";
string strTwo = "2";
//Convering both strings to integer type
int intToStr = int.Parse(strOne);
int intToStr2 = int.Parse(strTwo);
//Add them
int result = intToStr + intToStr2;
//Displays the addition result
MessageBox.Show(result.ToString());
Output:
3
Or can write like this:
//Direct convert to int and displays
MessageBox.Show((int.Parse(strOne) + int.Parse(strTwo)).ToString());
3
0 comments:
Post a Comment