本文整理汇总了C#中System.Collections.ArrayList.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# ArrayList.Remove方法的具体用法?C# ArrayList.Remove怎么用?C# ArrayList.Remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.ArrayList
的用法示例。
在下文中一共展示了ArrayList.Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Matches
public bool Matches(object one, object two)
{
var expected = new ArrayList(one.As<ICollection>());
var actual = new ArrayList(two.As<ICollection>());
foreach (object o in actual.ToArray())
{
if (expected.Contains(o))
{
actual.Remove(o);
expected.Remove(o);
}
}
foreach (object o in expected.ToArray())
{
if (actual.Contains(o))
{
actual.Remove(o);
expected.Remove(o);
}
}
return actual.Count == 0 && expected.Count == 0;
}
示例2: CleanThread
public static void CleanThread(ArrayList WorkThreadPool, int Timeout)
{
ThreadInfo CurrentThreadInfo;
for (int index = 0; index < WorkThreadPool.Count; index++)
{
CurrentThreadInfo = (ThreadInfo)WorkThreadPool[index];
// 清除已经结束的线程,不再保存信息
if (CurrentThreadInfo.ThreadName.ThreadState == ThreadState.Stopped)
{
WorkThreadPool.Remove(CurrentThreadInfo);
}
// 清除超时没有连接上的线程,强行杀掉,并从池中清除信息
// 超时按照毫秒计算
else if (CurrentThreadInfo.LiveTime > Timeout)
{
CurrentThreadInfo.ThreadName.Abort();
if (CurrentThreadInfo.ThreadName.Join(2000))
{
WorkThreadPool.Remove(CurrentThreadInfo);
}
}
// 每个活动线程的已生存了的时间增加500毫秒
else
{
CurrentThreadInfo.LiveTime += 500;
}
}
}
示例3: Main
static void Main(string[] args)
{
ArrayList al = new ArrayList();
al.Add("string");
al.Add('B');
al.Add(10);
al.Add(DateTime.Now);
ArrayList bl = new ArrayList(5);
al.Remove('B');
// 从al中删除第一个匹配的对象,如果al中不包含该对象,数组保持不变,不引发异常。
al.Remove('B');
al.RemoveAt(0);
al.RemoveRange(0, 1);
bl.Add(1);
bl.Add(11);
bl.Add(111);
bl.Insert(4, 1111);
int[] inttest = (int[])bl.ToArray(typeof(int));
foreach(int it in inttest)
Console.WriteLine(it);
int[] inttest2 = new int[bl.Count];
bl.CopyTo(inttest2);
ArrayList cl = new ArrayList();
cl.Add(1);
cl.Add("Hello, World!");
object[] ol = (object[])cl.ToArray(typeof(object));
// stringp[] os = (string[])cl.ToArray(typeof(string));
Console.WriteLine("The Capacity of new ArrayList: {0}", al.Capacity);
}
示例4: crash
public void crash(Fish fish, Form1 form, ArrayList fishList)
{
collision = aquaticAnimal.Bounds.IntersectsWith(fish.aquaticAnimal.Bounds);
if (collision==true)
{
if ((aquaticAnimal.ImageLocation.Equals(@"Resources\tiburon adulto.png") || aquaticAnimal.ImageLocation.Equals(@"Resources\tiburon hembra.png")) && (fish.aquaticAnimal.ImageLocation.Equals(@"Resources\Dorys.png") || fish.aquaticAnimal.ImageLocation.Equals(@"Resources\Nemo.png")))
{
fishList.Remove(fish);
fish.aquaticAnimal.Hide();
}
else if ((aquaticAnimal.ImageLocation.Equals(@"Resources\Dorys.png") || aquaticAnimal.ImageLocation.Equals(@"Resources\Nemo.png")) && (fish.aquaticAnimal.ImageLocation.Equals(@"Resources\tiburon adulto.png") || fish.aquaticAnimal.ImageLocation.Equals(@"Resources\tiburon hembra.png")))
{
fishList.Remove(aquaticAnimal);
aquaticAnimal.Hide();
}
else if ((aquaticAnimal.ImageLocation.Equals(@"Resources\Nemo.png") && fish.aquaticAnimal.ImageLocation.Equals(@"Resources\Nemo.png")))
{
fishList.Remove(fish);
aquaticAnimal.Hide();
}
else if ((aquaticAnimal.ImageLocation.Equals(@"Resources\tiburon adulto.png") && fish.aquaticAnimal.ImageLocation.Equals(@"Resources\tiburon adulto.png")))
{
fishList.Remove(aquaticAnimal);
aquaticAnimal.Hide();
}
}
}
示例5: Main
static void Main(string[] args)
{
Microsoft.Win32.SafeHandles.SafeFileHandle h;
string dEntry = "\\";
ArrayList entries = new ArrayList();
entries.Add(dEntry);
while (entries.Count != 0)
{
foreach (String entry in entries)
{
var attr = new Win.OBJECT_ATTRIBUTES(entry, 0);
var st = Win.NtOpenDirectoryObject(out h, 1, ref attr);
if (st < 0)
{
h.Dispose();
entries.Remove(entry);
break;
}
var bufsz = 1024;
var buf = Marshal.AllocHGlobal(bufsz);
uint context = 0, len;
while (true)
{
st = Win.NtQueryDirectoryObject(h, buf, bufsz, true, context == 0, ref context, out len);
if (st < 0)
{
entries.Remove(entry);
Marshal.FreeHGlobal(buf);
h.Dispose();
break;
}
var odi = (Win.OBJECT_DIRECTORY_INFORMATION)
Marshal.PtrToStructure(buf, typeof(Win.OBJECT_DIRECTORY_INFORMATION));
if (Convert.ToString(odi.TypeName) == "Mutant")
{
Console.WriteLine("0x{0:X2}:{1,-25}{2}", context, odi.TypeName, odi.Name);
parseMutex(Convert.ToString(odi.Name));
}
if (Convert.ToString(odi.TypeName) == "Directory")
{
if (entry == "\\")
{
entries.Add(entry + Convert.ToString(odi.Name));
}
else
{
entries.Add(entry + "\\" + Convert.ToString(odi.Name));
}
}
}
break;
}
}
}
示例6: play
private static void play()
{
Console.WriteLine("Would you prefer what is behind door number 1, 2, or 3?");
int min = 1;
int max = 4;
// Load the random numbers
ArrayList availableNumbers = new ArrayList();
for (int i = min; i < max; i++)
availableNumbers.Add(i);
// Assign the first number to the car's door number
int carValue = RandomNumber(min, max);
availableNumbers.Remove(carValue);
int boatValue = carValue;
int catValue;
string message;
// Randomly search for a value for the boat's door number
while (!availableNumbers.Contains(boatValue))
boatValue = RandomNumber(min, max);
availableNumbers.Remove(boatValue);
// Assign the cat value the remaining number
catValue = (int)availableNumbers[0];
// DEBUG
//Console.WriteLine(String.Format("CarValue: {0} BoatValue: {1} CatValue: {2}",carValue,boatValue,catValue));
// Read the user input
int userValue = readNumber(min, max);
// The 'CatValue' variable now only holds debug purposes, due to sufficient validation on the integer input
if (userValue == carValue)
message = "You won a new car!";
else if (userValue == boatValue)
message = "You won a new boat!";
else
message = "You won a new cat!";
Console.WriteLine(message);
Console.WriteLine("Do you want to play again? [Y/N]");
TextInfo ti = new CultureInfo("en-US", false).TextInfo;
if (String.Compare(ti.ToLower(readString()), "y") == 0)
{
// Repeat
Console.WriteLine("");
play();
}
else
// Cleanly exit
Environment.Exit(-1);
}
示例7: Main
static void Main()
{
Console.Write("List 1: ");
string[] names1 = Console.ReadLine().Split(' ');
Console.Write("List 2: ");
string[] names2 = Console.ReadLine().Split(' ');
ArrayList list1 = new ArrayList(names1);
ArrayList list2 = new ArrayList(names2);
for (int i = 0; i < list2.Count; i++)
{
while (list1.Contains(list2[i]))
{
list1.Remove(list2[i]);
}
}
for (int i = 0; i < list1.Count; i++)
{
Console.Write(list1[i]);
if (i < list1.Count - 1)
{
Console.Write(" ");
}
}
Console.WriteLine();
}
示例8: button3_Click
private void button3_Click(object sender, EventArgs e)
{
ArrayList arr = new ArrayList();
arr.Add(10);
arr.Add(20); //To add a new element at the end of collection
arr.Add(30);
arr.Add(40);
arr.Add(50);
arr.Add(60);
arr.Add(70);
arr.Add(80);
arr.Add(90);
arr[3] = 400; //To overwrite the value
MessageBox.Show(arr.Capacity.ToString());
arr.Insert(3, 1000);//insert in the middle
//shift the other elements =>index,value
foreach (object obj in arr)
{
listBox3.Items.Add(obj.ToString());
}
arr[12] = 10; //Runtime error
arr.Remove(10); //remove 10 <=value
arr.RemoveAt(1); //remove element at index 1 <=index
}
示例9: PrintWords
public void PrintWords()
{
var word = _dictionary.GetNextWord(_letterCount);
var i = 1;
while (word != null)
{
var containsValidLetters = true;
var tmpAlphabet = new ArrayList(_alphabet);
foreach (var item in word)
{
if (tmpAlphabet.Contains(item))
{
// такая буква есть в слове, удаляем её из алфавита,
// чтобы не использовать дважды
tmpAlphabet.Remove(item);
}
else
{
// DEBUG
//Console.WriteLine("***" + word + "***");
// END DEBUG
containsValidLetters = false;
break;
}
}
if (containsValidLetters)
{
Console.WriteLine("{0} {1}", i++, word);
}
word = _dictionary.GetNextWord(_letterCount);
}
}
示例10: RemoveOwnerWindow
/// <summary>
/// Remove owner window from hook tracing
/// </summary>
/// <param name="owner_window">owner window</param>
static public void RemoveOwnerWindow(IntPtr owner_window)
{
lock (static_lock_variable)
{
try
{
ICollection a = (ICollection)owner_windows.Clone();
ArrayList al = new ArrayList((ICollection)a);
al.Remove(owner_window);
owner_windows = (IntPtr[])al.ToArray(typeof(IntPtr));
owner_window_logs.Remove(owner_window);
if (owner_windows.Length < 1 && hook_id != IntPtr.Zero)
{
Win32.UnhookWindowsHookEx(hook_id);
hook_id = IntPtr.Zero;
}
}
catch (Exception e)
{
Log.Main.Exit(e);
}
}
}
示例11: is_anagram
private Boolean is_anagram(string word1, string word2)
{
int i;
ArrayList array_word1 = new ArrayList(Convert.ToInt32(word1.Length));
ArrayList array_word2 = new ArrayList(Convert.ToInt32(word2.Length));
word1 = word1.ToLower();
word2 = word2.ToLower();
if (word1.Length != word2.Length)
return false;
for (i = 0; i < word1.Length; i++)
array_word1.Add(word1[i].ToString());
for (i = 0; i < word2.Length; i++)
array_word2.Add(word2[i].ToString());
foreach (string val in array_word1)
{
if (array_word2.Contains(val))
array_word2.Remove(val);
}
if (array_word2.Count == 0)
return true;
else
return false;
}
示例12: Verify
public void Verify(ParameterList actualList)
{
var expectedKeys = new ArrayList(AllKeys);
var actualKeys = new ArrayList(actualList.AllKeys);
var unionKeys = new ArrayList();
var keys = (string[]) actualKeys.ToArray(typeof (string));
foreach (string key in keys)
{
if (expectedKeys.Contains(key))
{
unionKeys.Add(key);
expectedKeys.Remove(key);
actualKeys.Remove(key);
}
}
var failureCondition = new ParameterValidationFailureException();
checkForWrongParameterValues(unionKeys, actualList, failureCondition);
checkForMissingParameters(expectedKeys, failureCondition);
checkForUnExpectedParameters(actualList, actualKeys, failureCondition);
failureCondition.ThrowIfExceptions();
}
示例13: List
public List(Type type)
{
_myType = type;
_list = new ArrayList();
_list.Remove(0);
_index = 0;
}
示例14: Test
public void Test(int arg)
{
ArrayList items = new ArrayList();
items.Add(1);
items.AddRange(1, 2, 3);
items.Clear();
bool b1 = items.Contains(2);
items.Insert(0, 1);
items.InsertRange(1, 0, 5);
items.RemoveAt(4);
items.RemoveRange(4, 3);
items.Remove(1);
object[] newItems = items.GetRange(5, 2);
object[] newItems2 = items.GetRange(5, arg);
List<int> numbers = new List<int>();
numbers.Add(1);
numbers.AddRange(1, 2, 3);
numbers.Clear();
bool b2 = numbers.Contains(4);
numbers.Insert(1, 10);
numbers.InsertRange(2, 10, 3);
numbers.RemoveAt(4);
numbers.RemoveRange(4, 2);
int[] newNumbers = items.GetRange(5, 2);
int[] newNumbers2 = items.GetRange(5, arg);
string[] words = new string[5];
words[0] = "hello";
words[1] = "world";
bool b3 = words.Contains("hi");
string[] newWords = words.GetRange(5, 2);
string[] newWords2 = words.GetRange(5, arg);
}
示例15: Main
public static void Main(string[] args)
{
ArrayList list = new ArrayList();
Dog[] mas = new Dog[1];
Dog dog1 = new Dog("no name 0",12,0.1f);
list.Add(dog1);
list.Add(new chicken("no name 1",2,0.4f));
list.Add(new Dog("no name 2",1,0.1f));
mas[0] = dog1;
foreach(Dog d in list)
{
list.Remove(d);
Console.WriteLine("{0} - убит",d.name);
break;
}
cow[] muMas = new cow[3];
muMas[0] = new cow("no name 3",13,0.1f);
muMas[1] = new cow("no name 4",3,0.2f);
muMas[2] = new cow("no name 5",11,0.4f);
list.Add(muMas);
foreach(object d in list)
{
Console.WriteLine(d.ToString());
if(d.Equals(muMas))
foreach(cow c in muMas)
Console.WriteLine(c.ToString()+"; индексатор "+c[0]);
}
}