C# Print list of string array The Next CEO of Stack OverflowUseless output to console when printing result of ReadAllLinesC# & very new Programming in generalWhat is the difference between String and string in C#?How do I check if a list is empty?Create ArrayList from arrayFinding the index of an item given a list containing it in PythonHow to append something to an array?How to make a flat list out of list of lists?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?Why not inherit from List<T>?

Is there such a thing as a proper verb, like a proper noun?

Is there an equivalent of cd - for cp or mv

Why don't programming languages automatically manage the synchronous/asynchronous problem?

Is there a difference between "Fahrstuhl" and "Aufzug"?

Is it ok to trim down a tube patch?

Lucky Feat: How can "more than one creature spend a luck point to influence the outcome of a roll"?

From jafe to El-Guest

(How) Could a medieval fantasy world survive a magic-induced "nuclear winter"?

Is it OK to decorate a log book cover?

Is French Guiana a (hard) EU border?

What is the process for purifying your home if you believe it may have been previously used for pagan worship?

Why do we say 'Un seul M' and not 'Une seule M' even though M is a "consonne"

IC has pull-down resistors on SMBus lines?

TikZ: How to fill area with a special pattern?

Strange use of "whether ... than ..." in official text

What is the process for cleansing a very negative action

Why did early computer designers eschew integers?

Film where the government was corrupt with aliens, people sent to kill aliens are given rigged visors not showing the right aliens

How do I fit a non linear curve?

Towers in the ocean; How deep can they be built?

Aggressive Under-Indexing and no data for missing index

how one can write a nice vector parser, something that does pgfvecparseA=B-C; D=E x F;

How to use ReplaceAll on an expression that contains a rule

Small nick on power cord from an electric alarm clock, and copper wiring exposed but intact



C# Print list of string array



The Next CEO of Stack OverflowUseless output to console when printing result of ReadAllLinesC# & very new Programming in generalWhat is the difference between String and string in C#?How do I check if a list is empty?Create ArrayList from arrayFinding the index of an item given a list containing it in PythonHow to append something to an array?How to make a flat list out of list of lists?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?Why not inherit from List<T>?










4















I'm very new to c# and have a question, how do I print list of string arrays? I can do it from string[] using Console.WriteLine, but if I do that for list with forEach it just prints out System.String[], how do I write index when using for each?










share|improve this question






















  • Use the index and print it

    – A3006
    Feb 8 '17 at 11:38






  • 2





    if you want to print array values, you cannot just pass array to Console.WriteLine you should either print each item of array separately or convert array to string and then print that string. E.g. with String.Join(",", yourArray)

    – Sergey Berezovskiy
    Feb 8 '17 at 11:40
















4















I'm very new to c# and have a question, how do I print list of string arrays? I can do it from string[] using Console.WriteLine, but if I do that for list with forEach it just prints out System.String[], how do I write index when using for each?










share|improve this question






















  • Use the index and print it

    – A3006
    Feb 8 '17 at 11:38






  • 2





    if you want to print array values, you cannot just pass array to Console.WriteLine you should either print each item of array separately or convert array to string and then print that string. E.g. with String.Join(",", yourArray)

    – Sergey Berezovskiy
    Feb 8 '17 at 11:40














4












4








4








I'm very new to c# and have a question, how do I print list of string arrays? I can do it from string[] using Console.WriteLine, but if I do that for list with forEach it just prints out System.String[], how do I write index when using for each?










share|improve this question














I'm very new to c# and have a question, how do I print list of string arrays? I can do it from string[] using Console.WriteLine, but if I do that for list with forEach it just prints out System.String[], how do I write index when using for each?







c# arrays list






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 8 '17 at 11:37









atilas1atilas1

36227




36227












  • Use the index and print it

    – A3006
    Feb 8 '17 at 11:38






  • 2





    if you want to print array values, you cannot just pass array to Console.WriteLine you should either print each item of array separately or convert array to string and then print that string. E.g. with String.Join(",", yourArray)

    – Sergey Berezovskiy
    Feb 8 '17 at 11:40


















  • Use the index and print it

    – A3006
    Feb 8 '17 at 11:38






  • 2





    if you want to print array values, you cannot just pass array to Console.WriteLine you should either print each item of array separately or convert array to string and then print that string. E.g. with String.Join(",", yourArray)

    – Sergey Berezovskiy
    Feb 8 '17 at 11:40

















Use the index and print it

– A3006
Feb 8 '17 at 11:38





Use the index and print it

– A3006
Feb 8 '17 at 11:38




2




2





if you want to print array values, you cannot just pass array to Console.WriteLine you should either print each item of array separately or convert array to string and then print that string. E.g. with String.Join(",", yourArray)

– Sergey Berezovskiy
Feb 8 '17 at 11:40






if you want to print array values, you cannot just pass array to Console.WriteLine you should either print each item of array separately or convert array to string and then print that string. E.g. with String.Join(",", yourArray)

– Sergey Berezovskiy
Feb 8 '17 at 11:40













5 Answers
5






active

oldest

votes


















11














Simplest way is this:
using String.Join



string[] arr = new string[] "one", "two", "three", "four" ;
Console.WriteLine(String.Join("n", sarr));


Hope this helps.






share|improve this answer






























    2














    So you have list of string arrays, like this:



     List<string[]> data = new List<string[]>() 
    new string[] "A", "B", "C",
    new string[] "1", "2",
    new string[] "x", "yyyy", "zzz", "final",
    ;


    To print on, say, the Console, you can implement nested loops:



     foreach (var array in data) 
    Console.WriteLine();

    foreach (var item in array)
    Console.Write(" ");
    Console.Write(item);




    Or Join the items into the single string and then print it:



     using System.Linq;
    ...

    string report = string.Join(Environment.NewLine, data
    .Select(array => string.Join(" ", array)));

    Console.Write(report);


    Or combine both methods:



     foreach (var array in data) 
    Console.WriteLine(string.Join(" ", array));





    share|improve this answer
































      2














      string[] arr = new string[2]"foo","zoo"; // sample Initialize.

      // Loop over strings.
      foreach (string s in arr)

      Console.WriteLine(s);



      The console output:



      foo
      zoo





      share|improve this answer
































        0














        This works for me:



        var strArray = new string[] "abc","def","asd" ;
        strArray.ToList().ForEach(Console.WriteLine);





        share|improve this answer






























          0














          In a string array to get the index you do it:



          string[] names = new string[3] "Matt", "Joanne", "Robert" ;

          int counter = 0;
          foreach(var name in names.ToList())

          Console.WriteLine(counter.ToString() + ":-" + name);
          counter++;






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42112051%2fc-sharp-print-list-of-string-array%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            5 Answers
            5






            active

            oldest

            votes








            5 Answers
            5






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            11














            Simplest way is this:
            using String.Join



            string[] arr = new string[] "one", "two", "three", "four" ;
            Console.WriteLine(String.Join("n", sarr));


            Hope this helps.






            share|improve this answer



























              11














              Simplest way is this:
              using String.Join



              string[] arr = new string[] "one", "two", "three", "four" ;
              Console.WriteLine(String.Join("n", sarr));


              Hope this helps.






              share|improve this answer

























                11












                11








                11







                Simplest way is this:
                using String.Join



                string[] arr = new string[] "one", "two", "three", "four" ;
                Console.WriteLine(String.Join("n", sarr));


                Hope this helps.






                share|improve this answer













                Simplest way is this:
                using String.Join



                string[] arr = new string[] "one", "two", "three", "four" ;
                Console.WriteLine(String.Join("n", sarr));


                Hope this helps.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 8 '17 at 12:07









                PulkitGPulkitG

                222112




                222112























                    2














                    So you have list of string arrays, like this:



                     List<string[]> data = new List<string[]>() 
                    new string[] "A", "B", "C",
                    new string[] "1", "2",
                    new string[] "x", "yyyy", "zzz", "final",
                    ;


                    To print on, say, the Console, you can implement nested loops:



                     foreach (var array in data) 
                    Console.WriteLine();

                    foreach (var item in array)
                    Console.Write(" ");
                    Console.Write(item);




                    Or Join the items into the single string and then print it:



                     using System.Linq;
                    ...

                    string report = string.Join(Environment.NewLine, data
                    .Select(array => string.Join(" ", array)));

                    Console.Write(report);


                    Or combine both methods:



                     foreach (var array in data) 
                    Console.WriteLine(string.Join(" ", array));





                    share|improve this answer





























                      2














                      So you have list of string arrays, like this:



                       List<string[]> data = new List<string[]>() 
                      new string[] "A", "B", "C",
                      new string[] "1", "2",
                      new string[] "x", "yyyy", "zzz", "final",
                      ;


                      To print on, say, the Console, you can implement nested loops:



                       foreach (var array in data) 
                      Console.WriteLine();

                      foreach (var item in array)
                      Console.Write(" ");
                      Console.Write(item);




                      Or Join the items into the single string and then print it:



                       using System.Linq;
                      ...

                      string report = string.Join(Environment.NewLine, data
                      .Select(array => string.Join(" ", array)));

                      Console.Write(report);


                      Or combine both methods:



                       foreach (var array in data) 
                      Console.WriteLine(string.Join(" ", array));





                      share|improve this answer



























                        2












                        2








                        2







                        So you have list of string arrays, like this:



                         List<string[]> data = new List<string[]>() 
                        new string[] "A", "B", "C",
                        new string[] "1", "2",
                        new string[] "x", "yyyy", "zzz", "final",
                        ;


                        To print on, say, the Console, you can implement nested loops:



                         foreach (var array in data) 
                        Console.WriteLine();

                        foreach (var item in array)
                        Console.Write(" ");
                        Console.Write(item);




                        Or Join the items into the single string and then print it:



                         using System.Linq;
                        ...

                        string report = string.Join(Environment.NewLine, data
                        .Select(array => string.Join(" ", array)));

                        Console.Write(report);


                        Or combine both methods:



                         foreach (var array in data) 
                        Console.WriteLine(string.Join(" ", array));





                        share|improve this answer















                        So you have list of string arrays, like this:



                         List<string[]> data = new List<string[]>() 
                        new string[] "A", "B", "C",
                        new string[] "1", "2",
                        new string[] "x", "yyyy", "zzz", "final",
                        ;


                        To print on, say, the Console, you can implement nested loops:



                         foreach (var array in data) 
                        Console.WriteLine();

                        foreach (var item in array)
                        Console.Write(" ");
                        Console.Write(item);




                        Or Join the items into the single string and then print it:



                         using System.Linq;
                        ...

                        string report = string.Join(Environment.NewLine, data
                        .Select(array => string.Join(" ", array)));

                        Console.Write(report);


                        Or combine both methods:



                         foreach (var array in data) 
                        Console.WriteLine(string.Join(" ", array));






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Feb 8 '17 at 11:50

























                        answered Feb 8 '17 at 11:42









                        Dmitry BychenkoDmitry Bychenko

                        112k1099141




                        112k1099141





















                            2














                            string[] arr = new string[2]"foo","zoo"; // sample Initialize.

                            // Loop over strings.
                            foreach (string s in arr)

                            Console.WriteLine(s);



                            The console output:



                            foo
                            zoo





                            share|improve this answer





























                              2














                              string[] arr = new string[2]"foo","zoo"; // sample Initialize.

                              // Loop over strings.
                              foreach (string s in arr)

                              Console.WriteLine(s);



                              The console output:



                              foo
                              zoo





                              share|improve this answer



























                                2












                                2








                                2







                                string[] arr = new string[2]"foo","zoo"; // sample Initialize.

                                // Loop over strings.
                                foreach (string s in arr)

                                Console.WriteLine(s);



                                The console output:



                                foo
                                zoo





                                share|improve this answer















                                string[] arr = new string[2]"foo","zoo"; // sample Initialize.

                                // Loop over strings.
                                foreach (string s in arr)

                                Console.WriteLine(s);



                                The console output:



                                foo
                                zoo






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Feb 8 '17 at 12:34









                                Alexey Subach

                                4,90972144




                                4,90972144










                                answered Feb 8 '17 at 11:43









                                user114649user114649

                                211




                                211





















                                    0














                                    This works for me:



                                    var strArray = new string[] "abc","def","asd" ;
                                    strArray.ToList().ForEach(Console.WriteLine);





                                    share|improve this answer



























                                      0














                                      This works for me:



                                      var strArray = new string[] "abc","def","asd" ;
                                      strArray.ToList().ForEach(Console.WriteLine);





                                      share|improve this answer

























                                        0












                                        0








                                        0







                                        This works for me:



                                        var strArray = new string[] "abc","def","asd" ;
                                        strArray.ToList().ForEach(Console.WriteLine);





                                        share|improve this answer













                                        This works for me:



                                        var strArray = new string[] "abc","def","asd" ;
                                        strArray.ToList().ForEach(Console.WriteLine);






                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Feb 8 '17 at 11:43









                                        master2080master2080

                                        10613




                                        10613





















                                            0














                                            In a string array to get the index you do it:



                                            string[] names = new string[3] "Matt", "Joanne", "Robert" ;

                                            int counter = 0;
                                            foreach(var name in names.ToList())

                                            Console.WriteLine(counter.ToString() + ":-" + name);
                                            counter++;






                                            share|improve this answer



























                                              0














                                              In a string array to get the index you do it:



                                              string[] names = new string[3] "Matt", "Joanne", "Robert" ;

                                              int counter = 0;
                                              foreach(var name in names.ToList())

                                              Console.WriteLine(counter.ToString() + ":-" + name);
                                              counter++;






                                              share|improve this answer

























                                                0












                                                0








                                                0







                                                In a string array to get the index you do it:



                                                string[] names = new string[3] "Matt", "Joanne", "Robert" ;

                                                int counter = 0;
                                                foreach(var name in names.ToList())

                                                Console.WriteLine(counter.ToString() + ":-" + name);
                                                counter++;






                                                share|improve this answer













                                                In a string array to get the index you do it:



                                                string[] names = new string[3] "Matt", "Joanne", "Robert" ;

                                                int counter = 0;
                                                foreach(var name in names.ToList())

                                                Console.WriteLine(counter.ToString() + ":-" + name);
                                                counter++;







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Feb 8 '17 at 12:07









                                                Rui EstreitoRui Estreito

                                                22219




                                                22219



























                                                    draft saved

                                                    draft discarded
















































                                                    Thanks for contributing an answer to Stack Overflow!


                                                    • Please be sure to answer the question. Provide details and share your research!

                                                    But avoid


                                                    • Asking for help, clarification, or responding to other answers.

                                                    • Making statements based on opinion; back them up with references or personal experience.

                                                    To learn more, see our tips on writing great answers.




                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function ()
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42112051%2fc-sharp-print-list-of-string-array%23new-answer', 'question_page');

                                                    );

                                                    Post as a guest















                                                    Required, but never shown





















































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown

































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown







                                                    Popular posts from this blog

                                                    Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                                                    Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                                                    Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved