Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using:
Environment.NewLine + SB.AppendLine(string1, string1, string1)   ); }); 


would yield:
string1
string1
string1

however, I have declared var "R" and want to use it with AppendLine in a correct syntax to repeat "string1" for "R" times

Environment.NewLine + SB.AppendLine(string1, R)   ); }); 


Is it possible?

What I have tried:

Environment.NewLine + SB.AppendLine(string1, string1, string1)   ); });
Posted
Updated 25-Jan-21 2:24am
v3

1 solution

No, it wouldn't.
What you want is String.Join[^] which combines strings with a separator:
C#
string result = string.Join(Environment.NewLine, myCollectionOfStrings);
You can then generate your strings with R and combine them:
C#
string string1 = "Line ";
List<string> myCollectionOfStrings = new List<string>();
for (int R = 1; R < 10; R++)
    {
    myCollectionOfStrings.Add($"{string1}{R}");
    }
string result = string.Join(Environment.NewLine, myCollectionOfStrings);
 
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