+92 332 4229 857 99ProjectIdeas@Gmail.com

String Concat Function (C#.net)





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());

  Output:
            3

0 comments: