String Array contains values like {'2','4','8'}
if 8 is present, want to add 999 to it,if string array contains 999 want to add 8 to it.
If both 8 and 999 are present in array no need to add any value to array.
Have a look at the following:
public string[] Add8or999(string[] source)
{
string[] output = source;
if (source.Contains("8") && source.Contains("999"))
{
// what to do here?
}
else if (source.Contains("8"))
{
output = new string[source.Length + 1];
for (int i = 0; i < source.Length; i++)
{
output[i] = source[i];
}
output[source.Length] = "999";
}
else if (source.Contains("999"))
{
output = new string[source.Length + 1];
for (int i = 0; i < source.Length; i++)
{
output[i] = source[i];
}
output[source.Length] = "8";
}
return output;
}
Basic Usage:
string[] s = Add8or999(new string[] {"8", "9", "10"});
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加