本文整理汇总了C#中System.Collections.ArrayList.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.ArrayList.Remove方法的具体用法?C# System.Collections.ArrayList.Remove怎么用?C# System.Collections.ArrayList.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.ArrayList
的用法示例。
在下文中一共展示了System.Collections.ArrayList.Remove方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnRandomize_Click
private void btnRandomize_Click(object sender, EventArgs e)
{
var random = new Random();
var splitArray = new string[1];
var list = new System.Collections.ArrayList();
splitArray[0] = Environment.NewLine; // Used to split the list of owners in the textbox
// Add contents of textbox to array
list.AddRange(txtList.Text.Split(splitArray, StringSplitOptions.RemoveEmptyEntries));
txtList.Clear();
var length = list.Count;
// Loop through list, randomly selecting an item, adding it to the output list,
// then removing it from the list
for (var x = 0; x < length; x++)
{
var index = random.Next(list.Count);
txtList.Text += list[index] + Environment.NewLine;
list.Remove(list[index].ToString());
}
// Add output to clipboard
if (!String.IsNullOrEmpty(txtList.Text))
Clipboard.SetText(txtList.Text);
}
示例2: Main
static void Main(string[] args)
{
Car car1 = new Car();
car1.Make = "Oldsmobile";
car1.Model = "Cutlas Supreme";
Car car2 = new Car();
car2.Make = "Geo";
car2.Model = "Prism";
Book book1 = new Book();
book1.Author = "Robert Tabor";
book1.Title = "Microsoft .NET XML Web Services";
book1.ISBN = "0-000-00000-0";
// ArrayLists are dynamically sized, and support other
// cool features like sorting, removing items, etc.
System.Collections.ArrayList myArrayList = new System.Collections.ArrayList();
myArrayList.Add(car1);
myArrayList.Add(car2);
myArrayList.Add(book1);
myArrayList.Remove(book1); // if not remove the book we get a error in foreach
foreach (object o in myArrayList)
{
Console.WriteLine(((Car)o).Make);
}
Console.WriteLine("---------------------------------------------------------");
// Dictionaries allow you to save a key along with
// the value, and also support cool features.
// There are different dictionaries to choose from ...
System.Collections.Specialized.ListDictionary myDictionary
= new System.Collections.Specialized.ListDictionary();
myDictionary.Add(car1.Make, car1);
myDictionary.Add(car2.Make, car2);
myDictionary.Add(book1.Author, book1);
// Easy access to an element using its key
Console.WriteLine(((Car)myDictionary["Geo"]).Model);
// But since its not strongly typed, we can easily break it
// by adding a different type to the dictionary ...
// Obviously, I'm trying to retrieve a book here, and then get its ... model?
// Console.WriteLine(((Car)myDictionary["Robert Tabor"]).Model); <-- Error
Console.WriteLine("---------------------------------------------------------");
List<Car> myList = new List<Car>();
myList.Add(car1);
myList.Add(car2);
// myList.Add(book1); <-- error
foreach (Car car in myList)
{
Console.WriteLine(car.Model);
}
Console.WriteLine("---------------------------------------------------------");
Dictionary<string, Car> myDictionary2 = new Dictionary<string, Car>();
myDictionary2.Add(car1.Make, car1);
myDictionary2.Add(car2.Make, car2);
Console.WriteLine(myDictionary2["Geo"].Model);
// instance values on initialization
string[] names = { "Bob", "Steve", "Brian", "Chuck" };
Car car3 = new Car() { Make = "Oldsmobile", Model = "Cutlas Supreme" };
Car car4 = new Car() { Make = "Geo", Model = "Prism" };
Car car5 = new Car() { Make = "Nissan", Model = "Altima" };
List<Car> myList2 = new List<Car>() {
new Car { Make = "Oldsmobile", Model = "Cutlas Supreme"},
new Car { Make = "Geo", Model="Prism"},
new Car { Make = "Nissan", Model = "Altima"}
};
Console.ReadLine();
}
示例3: BuildArray
/// <exception cref="System.Exception"></exception>
internal virtual void BuildArray(int[] array, System.Collections.IList elements,
int currentPosition)
{
if (elements.Count == 0)
{
Post(array);
}
for (int i = 0; i < elements.Count; i++)
{
System.Collections.IList myElements = new System.Collections.ArrayList(elements);
int e = (int)myElements.Remove(i);
array[currentPosition] = e;
BuildArray(array, myElements, currentPosition + 1);
}
}
示例4: BuildRandomArray
/// <exception cref="System.Exception"></exception>
internal virtual void BuildRandomArray(int[] array, System.Collections.IList elements
, int currentPosition, int nbPossibilites)
{
if (elements.Count == 0)
{
Post(array);
}
for (int i = 0; i < nbPossibilites && i < elements.Count && nbSolutions < maxExecutions
; i++)
{
System.Collections.IList myElements = new System.Collections.ArrayList(elements);
int elementToPick = (int)(System.Math.Random() * elements.Count);
int e = (int)myElements.Remove(elementToPick);
array[currentPosition] = e;
BuildRandomArray(array, myElements, currentPosition + 1, nbPossibilites);
}
}
示例5: fringeSearch
/* Fringe Search
* Fringe search is a memory enchanced version of IDA* */
public bool fringeSearch()
{
//initialize:
System.Collections.ArrayList nowList = new System.Collections.ArrayList();
System.Collections.ArrayList laterList = new System.Collections.ArrayList();
System.Collections.ArrayList rejectedList = new System.Collections.ArrayList();
int limit = calcHvalue(startNode);
#if DEBUG
Globals.l2net_home.Add_Debug("start limit:" + limit);
#endif
bool found = false;
Globals.debugPath = nowList;
nowList.Add(startNode);
while (!found)
{
// Globals.l2net_home.Add_Debug("big loop...");
int fmin = INFINITY;
while (nowList.Count != 0)
{
AstarNode head = ((AstarNode)nowList[0]);
head.fvalue = calcFvalue(head);
#region check for goal
if (isNodeTarget(head, targetNode.x, targetNode.y))
{
found = true;
break;
}
#endregion
//check if head is over the limit
if (head.fvalue > limit)
{
//transfer head from nowlist to laterlist.
nowList.Remove(head);
laterList.Add(head);
//find the minimum of the nodes we will look at 'later'
fmin = Util.MIN(fmin, head.fvalue);
}
else
{
#region expand head's children on to now list
expand(head); //nodes are sorted by insert sort in this function
bool addedChildren = false;
foreach (AstarNode child in head.adjacentNodes)
{
//dont allow children already on path or adjacent to path or walls...
if (!isNodeIn(nowList, child) && !isNodeIn(laterList, child) && !isNodeIn(rejectedList, child))
{
if (child.passable == true)
{
//add child of head to front of nowlist
nowList.Insert(0, child);
addedChildren = true;
}
}
}
if (!addedChildren)
{
nowList.Remove(head);
rejectedList.Add(head);
}
#endregion
}
}
if (found == true)
break;
//set new limit
// Globals.l2net_home.Add_Debug("new limit:" + fmin);
limit = fmin;
//set now list to later list.
nowList = (System.Collections.ArrayList)laterList.Clone();
nowList.Sort();
Globals.debugPath = nowList;
laterList.Clear();
}
if (found == true)
{
//.........这里部分代码省略.........
示例6: Astar_start
/* Standard A* */
public bool Astar_start(AstarNode startNode, AstarNode targetNode)
{
System.Collections.ArrayList closedlist = new System.Collections.ArrayList();
System.Collections.ArrayList openlist = new System.Collections.ArrayList();
closedlist.Clear();
openlist.Clear();
startNode.fvalue = calcFvalue(startNode); //this sets g and h
openlist.Add(startNode);
while (openlist.Count > 0)
{
Globals.debugPath = pathNodes;
AstarNode xNode;
openlist.Sort();
xNode = ((AstarNode)openlist[0]);
if (xNode == targetNode)
{
pathNodes.Add(xNode);
return true;
}
openlist.Remove(xNode);
closedlist.Add(xNode);
pathNodes.Add(xNode);
findAdjacentNodes(xNode);
foreach (AstarNode yNode in xNode.adjacentNodes)
{
if (closedlist.Contains(yNode))
continue;
int tempGScore;
bool isBetter = false;
//todo add diagonals.
tempGScore = xNode.gvalue + HorizontalCost;
yNode.fvalue = calcFvalue(yNode);
if (openlist.Contains(yNode))
{
openlist.Add(yNode);
isBetter = true;
}
else if (tempGScore < yNode.gvalue)
isBetter = true;
else
isBetter = false;
if (isBetter)
{
yNode.gvalue = tempGScore;
yNode.hvalue = calcHvalue(yNode);
yNode.fvalue = yNode.gvalue + yNode.hvalue;
}
}
}
return false;
}
示例7: Main
static void Main(string[] args)
{
Car car1 = new Car();
car1.Make = "Oldsmobile";
car1.Model = "Cutlas Supreme";
Car car2 = new Car();
car2.Make = "Geo";
car2.Model = "Prism";
Book b1 = new Book();
b1.Author = "Robert Tabor";
b1.Title = "Microsoft .NET XML Web Services";
b1.ISBN = "0-000-00000-0";
//ArrayLists are dynamically sized, and support other
// cool features like sorting, removing items, etc.
System.Collections.ArrayList myArrayList = new System.Collections.ArrayList();
myArrayList.Add(car1);
myArrayList.Add(car2);
myArrayList.Add(b1);
myArrayList.Remove(b1);
foreach (object o in myArrayList)
{
Console.WriteLine(((Car)o).Make);//have to cast to car but then wont work with book
//strongly vs. weakly typed code
}
// Dictionaries allow you to save a key along with
// the value, and also support cool features.
// There are different dictionaries to choose from ...
/*
System.Collections.Specialized.ListDictionary myDictionary
= new System.Collections.Specialized.ListDictionary();
myDictionary.Add(car1.Make, car1);
myDictionary.Add(car2.Make, car2);
myDictionary.Add(b1.Author, b1);
// Easy acces to an element using its key
Console.WriteLine(((Car)myDictionary["Geo"]).Model);
// But since its not strongly types we can easily break it
// by adding a different type to the dictionary ...
// Obviously, I'm trying to retrieve a book here, and then get its ... model?
Console.WriteLine(((Car)myDictionary["Robert Tabor"]).Model);
*/
/*
//Generic collection List and we give it a type Car
List<Car> myList = new List<Car>();
myList.Add(car1);
myList.Add(car2);
//myList.Add(b1);
foreach (Car car in myList)
{
// No casting!
Console.WriteLine(car.Model);
}
*/
/*
Dictionary<string, Car> myDictionary = new Dictionary<string, Car>();
myDictionary.Add(car1.Make, car1);
myDictionary.Add(car2.Make, car2);
//myDictionary.Add(b1.Author, b1);
Console.WriteLine(myDictionary["Geo"].Model); //No casting!
*/
/*
List<Car> myList = new List<Car>() // This is all one long statement, 2 new instances of car in
// a new instance of the collection
{
new Car {Make = "Oldsmobile", Model = "Cutlas Supreme" },
new Car {Make = "Geo", Model = "Prism"}
};
*/
Console.ReadLine();
}
示例8: Main
static void Main(string[] args)
{
System.Collections.ArrayList M = new System.Collections.ArrayList();
string s = System.Console.ReadLine();
int N = int.Parse(s);
char c;
Int64 L;
int x;
for(int i=0;i<N;i++) {
s = System.Console.ReadLine();
c = s[0];
L = Int64.Parse(s.Substring(2));
M.Sort();
switch (c) {
case 'I':
if (!M.Contains(L))
{
M.Insert(0, L);
}
break;
case 'D':
x = Array.BinarySearch(M.ToArray(), L);
if(x < 0) {
System.Console.WriteLine("BRAK");
} else {
System.Console.WriteLine("OK");
M.Remove(L);
}
break;
case 'U':
x = Array.BinarySearch(M.ToArray(), L);
if (x >= 0) {
System.Console.WriteLine(M[x]);
} else if (~x < 0) {
System.Console.WriteLine("BRAK");
} else if ((~x) >= M.ToArray().Length)
{
System.Console.WriteLine("BRAK");
}
else {
System.Console.WriteLine(M[~x].ToString());
}
break;
case 'L':
x = Array.BinarySearch(M.ToArray(), L);
if (x >= 0)
{
System.Console.WriteLine(M[x]);
}
else if (~x <= 0)
{
System.Console.WriteLine("BRAK");
}
else if ((~x) > M.ToArray().Length)
{
System.Console.WriteLine("BRAK");
}
else
{
System.Console.WriteLine(M[~x-1].ToString());
}
break;
}
}
}