Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Printing list to output window

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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?

    #2
    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:
    Code:
    List<string> stringsList = new List<string>();
    Now you can loop through it using a variable counter like so:

    Code:
    for(int i = 0; i < stringsList.Count; i++) { 
    Print(stringsList[i]); 
    }
    Or you could use the object in a foreach to cut down some typing like so:

    Code:
    foreach(string item in stringList) { 
    Print(item); 
    }
    There are other ways to iterate through the list but without getting too fancy these are probably the two easiest ways.

    Please let me know if I may be of additional assistance.

    Comment


      #3


      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


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