Is there a way to combine formatted strings and/or arrays?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sachinko
    New Member
    • Sep 2010
    • 1

    #1

    Is there a way to combine formatted strings and/or arrays?

    Context :

    I read command line arguments using args object and print via formatted strings. Here is the sample code,

    Code:
    Console.WriteLine("I need to learn C# {0,9}", args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]);
    Is there a easy way to use the formatted strings and arrays instead of typing so much. Example i tried {0-9) to combine the formatted string but that didnt work and threw an exception - 'Input String was not in a correct format'

    I manily want my code to be compact as well type less :)
  • Subin Ninan
    New Member
    • Sep 2010
    • 91

    #2
    Make use of following code:

    Code:
    foreach (string argument in args)
    {
       Console.Write(argument + " ");
    }

    Comment

    Working...