Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Printing list to output window
Collapse
X
-
Printing list to output window
Is there an easy way to print the content of a list or do you have to use a loop?Tags: None
-
Hello,
Thank you for the question.
You have the option of using a for statement, a foreach statement when printing a list. Here are a couple of examples.
Lets say you have a list of strings or:
Now you can loop through it using a variable counter like so:Code:List<string> stringsList = new List<string>();
Or you could use the object in a foreach to cut down some typing like so:Code:for(int i = 0; i < stringsList.Count; i++) { Print(stringsList[i]); }
There are other ways to iterate through the list but without getting too fancy these are probably the two easiest ways.Code:foreach(string item in stringList) { Print(item); }
Please let me know if I may be of additional assistance.
-
Code:using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace HelloWorld { public class Program { public static void Main(string[] args) { List<double> myPartyAges = new List<double> { 35.32, 0, 39.21, 42.43, 88.20, 0, 39.21, 42.32, 99.01 }; //myPartyAges.RemoveAll(i => i == 0); //myPartyAges.Distinct().ToList(); //myPartyAges.Union(myPartyAges).ToList(); //foreach (double i in myPartyAges) //Console.WriteLine(i); var dict = new Dictionary<double, double>(); foreach (var s in myPartyAges) { dict.TryAdd(s, 1); } var distinctList = dict.Keys.ToList(); distinctList.RemoveAll(i => i == 0); foreach (double s in distinctList) { Console.WriteLine(s); } } } }
Comment
-
Hello PaulMohn,
Did you need help with something? There is no question or information attached to your post. For anyone that comes across this code it cannot be directly used from NinjaTrader, this is a standard C# console application so it would need to be tested in external tools like visual studio.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
633 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
364 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
567 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
568 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment