Is it possible to include a C# variable in a string variable without using a concatenator?

前端 未结 14 1842
遥遥无期
遥遥无期 2021-02-14 07:02

Does .NET 3.5 C# allow us to include a variable within a string variable without having to use the + concatenator (or string.Format(), for that matter).

For example (In

14条回答
  •  我寻月下人不归
    2021-02-14 07:49

    If you are just trying to avoid concatenation of immutable strings, what you're looking for is StringBuilder.

    Usage:

    string parameterName = "Example";
    int parameterValue = 1;
    Stringbuilder builder = new StringBuilder();
    builder.Append("The output parameter ");
    builder.Append(parameterName);
    builder.Append("'s value is ");
    builder.Append(parameterValue.ToString());
    string totalExample = builder.ToString();
    

提交回复
热议问题