本文整理汇总了C#中System.Collections.ArrayList.RemoveAt方法的典型用法代码示例。如果您正苦于以下问题:C# ArrayList.RemoveAt方法的具体用法?C# ArrayList.RemoveAt怎么用?C# ArrayList.RemoveAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.ArrayList
的用法示例。
在下文中一共展示了ArrayList.RemoveAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Canonicalize
/// <summary>
/// Return the canonical form of a path.
/// </summary>
public static string Canonicalize( string path )
{
ArrayList parts = new ArrayList(
path.Split( DirectorySeparatorChar, AltDirectorySeparatorChar ) );
for( int index = 0; index < parts.Count; )
{
string part = (string)parts[index];
switch( part )
{
case ".":
parts.RemoveAt( index );
break;
case "..":
parts.RemoveAt( index );
if ( index > 0 )
parts.RemoveAt( --index );
break;
default:
index++;
break;
}
}
return String.Join( DirectorySeparatorChar.ToString(), (string[])parts.ToArray( typeof( string ) ) );
}
示例2: SimpleCollisionDetection
/// <summary>
/// Simple and fast label collision detection.
/// </summary>
/// <param name="labels"></param>
public static IEnumerable SimpleCollisionDetection(IList labels)
{
ArrayList labelList = new ArrayList(labels);
labelList.Sort(); // sort labels by intersection tests of the label's collision box
//remove labels that intersect other labels
for (int i = labelList.Count - 1; i > 0; i--)
{
Label2D label1 = labelList[i] as Label2D;
Label2D label2 = labelList[i - 1] as Label2D;
if (label1 == null)
{
labelList.RemoveAt(i);
continue;
}
if (label1.CompareTo(label2) == 0)
{
if (label1.Priority > label2.Priority)
{
labelList.RemoveAt(i - 1);
}
else
{
labelList.RemoveAt(i);
}
}
}
return labelList;
}
示例3: Merge
public static void Merge(ArrayList al1, ArrayList al2)
{
for (int i = 0; i < al1.Count; i++)
{
for (int j = i + 1; j < al1.Count; j++)
{
int start = int.Parse(al1[i].ToString());
int end = int.Parse(al2[i].ToString());
int point1 = int.Parse(al1[j].ToString());
int point2 = int.Parse(al2[j].ToString());
if (point1 >= start && point1 <= end)
{
if (point2 >= end)
{
al2[i] = (object)point2;
}
al1.RemoveAt(j);
al2.RemoveAt(j);
j -= 1;
}
if (point2 >= start && point2 <= end)
{
if (point1 <= start)
{
al1[i] = (object)point1;
}
al1.RemoveAt(j);
al2.RemoveAt(j);
j -= 1;
}
}
}
}
示例4: SwapPosition
public static void SwapPosition(ArrayList lista, Object node1, Object node2)
{
int exp1idx = lista.IndexOf(node1);
int exp2idx = lista.IndexOf(node2);
lista.RemoveAt(exp1idx);
lista.Insert(exp1idx, node2);
lista.RemoveAt(exp2idx);
lista.Insert(exp2idx, node1);
}
示例5: Execute
public void Execute(IRocketPlayer caller, string[] command)
{
if (command.Length < 2)
{
this.SendUsage(caller);
return;
}
var name = command.GetStringParameter(0);
var typeName = command.GetStringParameter(1).ToLower();
if (RegionsPlugin.Instance.GetRegion(name, true) != null)
{
UnturnedChat.Say(caller, "A region with this name already exists!", Color.red);
return;
}
var type = RegionType.RegisterRegionType(typeName);
if (type == null)
{
var types = "";
foreach (var t in RegionType.GetTypes())
{
if (types == "")
{
types = t;
continue;
}
types += ", " + t;
}
UnturnedChat.Say(caller, "Unknown type: " + typeName + "! Available types: " + types, Color.red);
return;
}
var args = new ArrayList(command);
args.RemoveAt(0); // remove name...
args.RemoveAt(0); // remove type...
var region = type.OnCreate(caller, name, (string[]) args.ToArray(typeof(string)));
if (region == null)
{
UnturnedChat.Say(caller, "Could't create region!", Color.red);
return;
}
RegionsPlugin.Instance.Regions.Add(region);
RegionsPlugin.Instance.OnRegionCreated(region);
region.SetFlag("EnterMessage", "Entered region: {0}", new List<GroupValue>());
region.SetFlag("LeaveMessage", "Left region: {0}", new List<GroupValue>());
RegionsPlugin.Instance.Configuration.Save();
UnturnedChat.Say(caller, "Successfully created region: " + name, Color.green);
}
示例6: ReduceRects
public override void ReduceRects(ref ArrayList a_aRects)
{
//TODO: if more than N rects, sort them by area (or locX?)
//TODO: check the area affected - if it's small, just do a join!
int nCnt = a_aRects.Count;
if (nCnt > 100) //more than 100 tests will take too much time - just do a join!
{
Rectangle rctUnion = RectsUnion(a_aRects);
a_aRects.Clear();
a_aRects.Add(rctUnion);
return;
}
Rectangle rct = new Rectangle(0,0,0,0);
bool bGotRect = false;
int nCheckThisPos = nCnt-1;
for(;;)
{
if (bGotRect == false)
{
rct = (Rectangle)a_aRects[nCheckThisPos];
bGotRect = true;
a_aRects.RemoveAt(nCheckThisPos);
}
//if (m_bMakeCallback) then makeCallback(m_plCallbackInfo, me, #Draw, [#AllRects:a_aRects, #CheckThis:rct])
int nJoinedRectAtPos = ReduceRectsSub(ref a_aRects, rct);
// if (m_bMakeCallback) then makeCallback(m_plCallbackInfo, me, #Draw, [#AllRects:a_aRects])
//Added step: if there's been a join, the current dirtyRect list must be rechecked
//because maybe the new rect should join with another
if (nJoinedRectAtPos >= 0)
{
if (a_aRects.Count == 1)
return;
rct = (Rectangle)a_aRects[nJoinedRectAtPos];
a_aRects.RemoveAt(nJoinedRectAtPos);
nCheckThisPos = a_aRects.Count;
}
else
{
nCheckThisPos--;
bGotRect = false;
if (nCheckThisPos <= 0)
return;
}
}
}
示例7: DeleteArraylist
public static void DeleteArraylist(ArrayList arraylist)
{
Console.WriteLine("количество элементов arraylist {0}", arraylist.Count);
int del = arraylist.Count;
Stopwatch sw = Stopwatch.StartNew();
arraylist.RemoveAt(0);
arraylist.RemoveAt((arraylist.Count-1)/2);
arraylist.RemoveAt(arraylist.Count -1);
Console.WriteLine("количество элементов arraylist после удаления {0}", arraylist.Count);
Console.WriteLine("Время удаления из arraylist = {0}", sw.Elapsed);
Console.ReadLine();
}
示例8: Main
static void Main(string[] args)
{
// Create an ArrayList
ArrayList al = new ArrayList();
// Add some elements
al.Add("foo");
al.Add(3.7);
al.Add(5);
al.Add(false);
// List them
Console.WriteLine("Count={0}",al.Count);
for(int i = 0; i < al.Count; i++)
Console.WriteLine("al[{0}]={1}", i, al[i]);
// Remove the element at index 1
al.RemoveAt(1);
// List them
Console.WriteLine("Count={0}",al.Count);
for(int i = 0; i < al.Count; i++)
Console.WriteLine("al[{0}]={1}", i, al[i]);
IEnumerator ie = al.GetEnumerator();
while(ie.MoveNext())
Console.WriteLine(ie.Current);
}
示例9: GetNonPropertyMethods
internal static MethodInfo[] GetNonPropertyMethods(Type type)
{
MethodInfo[] aMethods = type.GetMethods();
ArrayList methods = new ArrayList(aMethods);
PropertyInfo[] props = type.GetProperties();
foreach (PropertyInfo prop in props)
{
MethodInfo[] accessors = prop.GetAccessors();
foreach (MethodInfo accessor in accessors)
{
for (int i = 0; i < methods.Count; i++)
{
if ((MethodInfo)methods[i] == accessor)
methods.RemoveAt(i);
}
}
}
MethodInfo[] retMethods = new MethodInfo[methods.Count];
methods.CopyTo(retMethods);
return retMethods;
}
示例10: fun1
public void fun1()
{
ArrayList a1 = new ArrayList();
a1.Add(1);
a1.Add('c');
a1.Add("string1");
ArrayList al2 = new ArrayList();
al2.Add('a');
al2.Add(5);
int n = (int)a1[0];
Console.WriteLine(n);
a1[0] = 20;
Console.WriteLine(a1.Count);
Console.WriteLine(a1.Contains(55));
Console.WriteLine(a1.IndexOf(55));
//int[] num = (int[])a1.ToArray();
a1.Add(45);
a1.Add(12);
a1.Add(67);
a1.Insert(1, "new value");
//a1.AddRange(al2);
a1.InsertRange(1, al2);
a1.Remove("string1");
a1.RemoveAt(2);
a1.RemoveRange(0, 2);
foreach (object o in a1)
{
Console.WriteLine(o.ToString());
}
}
示例11: CreateMenuItems
/// <summary>
/// Creates menu items for the specified MenuDefinitionEntryCollection.
/// </summary>
/// <param name="commandManager">The CommandManager to use.</param>
/// <param name="menuDefinitionEntryCollection">The MenuDefinitionEntryCollection to create menu items for.</param>
/// <returns>The menu items.</returns>
public static MenuItem[] CreateMenuItems(CommandManager commandManager, MenuType menuType, MenuDefinitionEntryCollection menuDefinitionEntryCollection)
{
ArrayList menuItemArrayList = new ArrayList();
for (int position = 0; position < menuDefinitionEntryCollection.Count; position++)
{
MenuItem[] menuItems = menuDefinitionEntryCollection[position].GetMenuItems(commandManager, menuType);
if (menuItems != null)
menuItemArrayList.AddRange(menuItems);
}
// remove leading, trailing, and adjacent separators
for (int i = menuItemArrayList.Count - 1; i >= 0; i--)
{
if (((MenuItem)menuItemArrayList[i]).Text == "-")
{
if (i == 0 || // leading
i == menuItemArrayList.Count - 1 || // trailing
((MenuItem)menuItemArrayList[i - 1]).Text == "-") // adjacent
{
menuItemArrayList.RemoveAt(i);
}
}
}
return (menuItemArrayList.Count == 0) ? null : (MenuItem[])menuItemArrayList.ToArray(typeof(MenuItem));
}
示例12: 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);
}
示例13: 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
}
示例14: BackSpaceButton_Click
private void BackSpaceButton_Click(object sender, EventArgs e)
{
if (txtKitchenText.Text == null || txtKitchenText.Text.Length<1)
{
return;
}
try
{
m_arrList = new ArrayList();
foreach (Char obj in txtKitchenText.Text)
{
m_arrList.Add(obj);
}
m_arrList.RemoveAt(m_arrList.Count - 1);
string currentText = "";
foreach (char o in m_arrList)
{
currentText += o;
}
txtKitchenText.Text = currentText;
}
catch (Exception exp)
{
throw exp;
}
}
示例15: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
//1. create empty ArrayList
ArrayList al = new ArrayList();
//2. add element into array list
al.Add("Dog");
al.Add("Cat");
al.Add("Elephant");
al.Add("Lion");
al.Add("Cat");
al.Add("Platypus");
//3. bind above arrayList to first list box
lbOriginal.DataSource = al;
lbOriginal.DataBind();
//4. change (insert -> remove ->remove)
al.Insert(1, "Chicken~~~");
al.Remove("Cat");
al.RemoveAt(0);
//5. bind the result into second list box
lbChanged.DataSource = al;
lbChanged.DataBind();
}