Search code examples
javac#stringstring-formatting

Java string format to c# string format


Hi is there a way to convert the java string format to c#? I want to code in c# but I don't know how I can translate this java CODE:

String credentials = String.format("%s:%s", param1, param2);

I have already tried to translate it to c# but it doesn't work for me here is my c# code:

string credentials = string.Format("%s:%s", param1, param2);

Solution

  • You can use string interpolation (more at $ - string interpolation (C# reference)):

    string credentials = $"{param1}:{param2}";
    

    Otherwise it's composite formatting with indexes (see Composite formatting):

    string.Format("{0}:{1}", param1, param2);