1
Answer

Basic List<> syntax inquiry

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace LISTCOLLECTIONS

{

class Program

{

static void Main(string[] args)

{

List<Order> orderList = datalist();

var orders = from o in orderList

select o;

foreach (var o in orders)

Console.WriteLine("Order ID is: {0}", o.OrderID.ToString());

Console.ReadLine();

}

class Order

{ public int OrderID { get; set; } }

static private List<Order> datalist()

{

List<Order> orderList = new List<Order>();

Order o1 = new Order();

o1.OrderID = 123;

return orderList;

}

}

}

//WHEN I RUN THIS EXAMPLE THE CONSOLE WINDOW OPEN WITH BLINKING CURSOR WITHOUT DISPLAYING  Console.WriteLine("Order ID is: {0}", o.OrderID.ToString()); WHAT I AM DOING WRONG
Answers (1)
0
Glenn Patton

Glenn Patton

NA 333 60.7k 12y
Hi All,

I have managed to get the correct version of the driver I need here is the code to do it!
 private void button5_Click(object sender, EventArgs e)
        {
     
            List<SignedDriver> drivers = GetDriverInfo();
          
            foreach (SignedDriver driver in drivers)
                listBox1.Items.Add(driver.DeviceName+","+driver.DriverDate+","+driver.DriverVersion);
        
        }

        private void button6_Click(object sender, EventArgs e)
        {
            int index = -1;
          
            index = listBox1.FindString("USB Serial Converter,20120410000000.******+***");
            if (index == -1)
            {
                MessageBox.Show(" Driver Not Found ","",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("index = " + index.ToString() + " , " + listBox1.Items[index].ToString(),"",MessageBoxButtons.OK,MessageBoxIcon.Information);
                textBox2.Text = listBox1.Items[index].ToString();
            }




        }

        private void button7_Click(object sender, EventArgs e)
        {
            const char Comma = ',';
            string Target;
            string Version_Number = "";
            string output = "";
            int count = 0;

           
            Target = textBox2.Text;

          
            foreach (string subString in Target.Split(Comma))
            {
                output += subString + ";";
                count++;
                if(count == 3)
                {
                    Version_Number = subString;
                    break;
                }

           }

            MessageBox.Show("Version of driver is "+Version_Number,"",MessageBoxButtons.OK,MessageBoxIcon.Information);
        }

       

    }
 That took a lot of doing to find out the how and why, the Service Controller method will not allow the info I needed (I hope!)
Glenn