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 CarlTrading, 03-31-2026, 09:41 PM
|
1 response
153 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
89 views
1 like
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
133 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
128 views
1 like
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
107 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment