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>?
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
add a comment |
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
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 toConsole.WriteLine
you should either print each item of array separately or convert array to string and then print that string. E.g. withString.Join(",", yourArray)
– Sergey Berezovskiy
Feb 8 '17 at 11:40
add a comment |
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
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
c# arrays list
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 toConsole.WriteLine
you should either print each item of array separately or convert array to string and then print that string. E.g. withString.Join(",", yourArray)
– Sergey Berezovskiy
Feb 8 '17 at 11:40
add a comment |
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 toConsole.WriteLine
you should either print each item of array separately or convert array to string and then print that string. E.g. withString.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
add a comment |
5 Answers
5
active
oldest
votes
Simplest way is this:
using String.Join
string[] arr = new string[] "one", "two", "three", "four" ;
Console.WriteLine(String.Join("n", sarr));
Hope this helps.
add a comment |
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));
add a comment |
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
add a comment |
This works for me:
var strArray = new string[] "abc","def","asd" ;
strArray.ToList().ForEach(Console.WriteLine);
add a comment |
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++;
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Simplest way is this:
using String.Join
string[] arr = new string[] "one", "two", "three", "four" ;
Console.WriteLine(String.Join("n", sarr));
Hope this helps.
add a comment |
Simplest way is this:
using String.Join
string[] arr = new string[] "one", "two", "three", "four" ;
Console.WriteLine(String.Join("n", sarr));
Hope this helps.
add a comment |
Simplest way is this:
using String.Join
string[] arr = new string[] "one", "two", "three", "four" ;
Console.WriteLine(String.Join("n", sarr));
Hope this helps.
Simplest way is this:
using String.Join
string[] arr = new string[] "one", "two", "three", "four" ;
Console.WriteLine(String.Join("n", sarr));
Hope this helps.
answered Feb 8 '17 at 12:07
PulkitGPulkitG
222112
222112
add a comment |
add a comment |
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));
add a comment |
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));
add a comment |
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));
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));
edited Feb 8 '17 at 11:50
answered Feb 8 '17 at 11:42
Dmitry BychenkoDmitry Bychenko
112k1099141
112k1099141
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
edited Feb 8 '17 at 12:34
Alexey Subach
4,90972144
4,90972144
answered Feb 8 '17 at 11:43
user114649user114649
211
211
add a comment |
add a comment |
This works for me:
var strArray = new string[] "abc","def","asd" ;
strArray.ToList().ForEach(Console.WriteLine);
add a comment |
This works for me:
var strArray = new string[] "abc","def","asd" ;
strArray.ToList().ForEach(Console.WriteLine);
add a comment |
This works for me:
var strArray = new string[] "abc","def","asd" ;
strArray.ToList().ForEach(Console.WriteLine);
This works for me:
var strArray = new string[] "abc","def","asd" ;
strArray.ToList().ForEach(Console.WriteLine);
answered Feb 8 '17 at 11:43
master2080master2080
10613
10613
add a comment |
add a comment |
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++;
add a comment |
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++;
add a comment |
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++;
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++;
answered Feb 8 '17 at 12:07
Rui EstreitoRui Estreito
22219
22219
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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. withString.Join(",", yourArray)
– Sergey Berezovskiy
Feb 8 '17 at 11:40