using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<string> ul = new List<string>();
Process[] procs = Process.GetProcesses();
int u = 0;
foreach (Process proc in procs)
{
ul[u] = proc.ProcessName;
u++;
}
}
}
}
I want to move each process name into my arraylist each time loop executed but i’m getting outofbound Exception. please provide some sample codes. thanks in advance…
Try using the .Add() function, like this:
A List<> when created, has a default size, and in your code elements get added until that size is full (at which point the next ‘insert’ fails. The add() method checks to see if this size limit is no longer enough and increases the size of the list when required.
This code also eliminates the need for a couple of your variables.