Alternative string concatenation of a two string in C#

public static string GetString(string string1,string string2)
{
char[] str1 = string1.ToCharArray();
char[] str2 = string2.ToCharArray();

string finalString = “”;
int length = str1.Length > str2.Length ? str2.Length : str1.Length;
for (int i = 0; i < length ; i++)
{
finalString = finalString + str1[i] + str2[i];
}
if (str1.Length > str2.Length)
{
int difference = str1.Length – str2.Length;
for (int i = 0; i < difference; i++)
{
char rem = str1[str2.Length + i];
finalString = finalString + rem;
}

}
else
{
int difference = str2.Length – str1.Length;
for (int i = 0; i < difference; i++)
{
char rem = str2[str1.Length + i];
finalString = finalString + rem;
}
}
return finalString;
}

string finalString = GetString(“USA”, “INDIA”);

Ouput : UISNADIA

One thought on “Alternative string concatenation of a two string in C#

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s