/// <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; }
/// <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 ) ) ); }
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; } } } }
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); }
public void RemoveAt(int index) { lock (this) { EventType.RemoveAt(index); BytesToRead.RemoveAt(index); Source.RemoveAt(index); NumEventsHandled--; } }
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); }
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; } } }
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(); }
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); }
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; } }
/// <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)); }
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); }
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()); } }
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 }
private CKnote ErmittleEndKnoten(ArrayList verbindungen, ArrayList knoten) { foreach (CVerbindung verbindung in verbindungen) for (int i = 0; i <= knoten.Count - 1; i++) if (verbindung.GetStart() == (CKnote)knoten[i]) knoten.RemoveAt(i); return (CKnote)knoten[knoten.Count - 1]; }
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(); }
/// <summary> /// Removes the element at the top of the stack and returns it. /// </summary> /// <param name="stack">The stack where the element at the top will be returned and removed.</param> /// <returns>The element at the top of the stack.</returns> public static System.Object Pop(System.Collections.ArrayList stack) { System.Object obj = stack[stack.Count - 1]; stack.RemoveAt(stack.Count - 1); return(obj); }
static void Main(string[] args) { ArrayList a = new ArrayList(); a.Add(123); a.Add("BARD"); a.Add(34.689); a.Insert(2, 'A'); a.Remove(123); a.RemoveAt(2); foreach (Object o in a) { Console.WriteLine(o.ToString()); } //Student s = new Student(); //s.GetData(); //a.Add(s); //foreach (Object o in a) //{ // if (o.GetType().ToString() == "ArrayListSample.Student") // { // Student s1 = (Student)o; // s1.ShowData(); // } //} //Console.WriteLine("No of elements are:" +a.Count); Console.Read(); }
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); }
public Cliente_Admin(bool cumple) { InitializeComponent(); cbox_filtro_producto.SelectedIndex = 0; ArrayList lista = new ArrayList(); // nombre if (cbox_filtro_producto.SelectedIndex == 0) { string buscarse = "and c.nombre like '%%'"; lista = DatosCliente.getClientes(buscarse); } for (int x = lista.Count; x > 0; x--) { if (((Cliente)lista[x - 1]).Nacimiento.Day != DateTime.Today.Day || ((Cliente)lista[x - 1]).Nacimiento.Month != DateTime.Today.Month) { lista.RemoveAt(x - 1); } } listaVacia.Clear(); listaVacia = lista; bdd_clientes.DataSource = listaVacia; }
static void Main(string[] args) { Console.Write(@"В кругу стоят N человек, пронумерованных от 1 до N. При ведении счета по кругу вычёркивается каждый второй человек, пока не останется один. Введите количество человек: "); int n = int.Parse(Console.ReadLine()); ArrayList array = new ArrayList(n); for (int t = 1; t <= n; t++) { array.Add(t); Console.Write(array[t - 1] + " "); } Console.WriteLine("\n\nОтдельное вычеркивание каждого второго элемента"); int i = 1; while (array.Count != 1) { array.RemoveAt(i); ++i; if (i > array.Count) { i = 1; } if (i == array.Count) { i = 0; } for (int t = 0; t < array.Count; t++) { Console.Write(array[t] + " "); } Console.WriteLine(); } Console.ReadKey(); }
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; }
/// <summary> /// Splits string consisting of fields separated by /// whitespace into an array of strings. /// </summary> /// <param name="str">string to split</param> public static string[] Split(string str) { ArrayList allTokens = new ArrayList(str.Split(null)); for (int i = allTokens.Count - 1; i >= 0; i--) if (((string)allTokens[i]).Trim().Length == 0) allTokens.RemoveAt(i); return (string[])allTokens.ToArray(typeof(string)); }
/////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// A message handler for when the user moves the mouse over the font image while we are /// creating the glyph strips /// </summary> /////////////////////////////////////////////////////////////////////////////////////////// private void pictureBoxZoomFontImage_CreateStrips_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { // Get the mouse position in image coordinates Point mousePosImg = pictureBoxZoomFontImage.ClientToImage(new Point(e.X, e.Y)); // If we are dragging a strip if (m_DraggingStripIndex != -1) { // If we are leaving the paint box if (e.Y < 0 || e.Y > pictureBoxZoomFontImage.Height) { // Remove this drag strip and stop dragging m_GlyphStrips.RemoveAt(m_DraggingStripIndex); m_DraggingStripIndex = -1; } // Else we are still in the box else { // Move the strip int stripY = (int)m_GlyphStrips[m_DraggingStripIndex]; stripY += mousePosImg.Y - m_DraggingLastY; m_GlyphStrips[m_DraggingStripIndex] = stripY; // Store the mouse position m_DraggingLastY = mousePosImg.Y; } // Redraw pictureBoxZoomFontImage.Refresh(); } // Else see if we are over an existing strip else { // If we are over a strip if (IsOverGlyphStrip(mousePosImg) != -1) { Cursor = Cursors.SizeNS; } // Else we aren't else { Cursor = Cursors.Default; } } }
/// <summary> /// Updates the thrust effects (vapor trail) /// </summary> public void UpdateThrustEffect(float ElapsedTime, int NumParticlesToEmit, System.Drawing.Color EmitColor, System.Drawing.Color FadeColor, Vector3 Position) { time += ElapsedTime; location = Position; for (int i = particlesList.Count - 1; i >= 0; i--) { Particle p = (Particle)particlesList[i]; // Calculate new position float fT = time - p.creationTime; p.fadeProgression -= ElapsedTime * 0.60f; p.positionVector = p.initialVelocity * fT + p.initialPosition; p.velocityVector.Z = 0; if (p.fadeProgression < 0.0f) { p.fadeProgression = 0.0f; } // Kill old particles if (p.fadeProgression <= 0.0f) { // Kill particle freeParticles.Add(p); particlesList.RemoveAt(i); particles--; } else { particlesList[i] = p; } } // Emit new particles int particlesEmit = particles + NumParticlesToEmit; while (particles < particlesLimit && particles < particlesEmit) { Particle particle; if (freeParticles.Count > 0) { particle = (Particle)freeParticles[0]; freeParticles.RemoveAt(0); } else { particle = new Particle(); } // Emit new particle particle.initialPosition = Position + offset; particle.positionVector = particle.initialPosition; particle.velocityVector = particle.initialVelocity; particle.diffuseColor = EmitColor; particle.fadeColor = FadeColor; particle.fadeProgression = 1.0f; particle.creationTime = time; particlesList.Add(particle); particles++; } }
public void CurvefitValue(int x) { for (int i = 0; i < Coefficients.Count(); i++) PolyfitValue += Coefficients[i] * Math.Pow(x, i); ArrayList al = new ArrayList(Predictions); al.RemoveAt(0); al.Add(PolyfitValue); PredictionsNew = (double[])al.ToArray(typeof(double)); }
public void Explode(int NumParticlesToEmit, Vector3 vPosition) { // Emit new particles int particlesEmit = particles + NumParticlesToEmit; while (particles < particlesLimit && particles < particlesEmit) { Particle particle; if (freeParticles.Count > 0) { particle = (Particle)freeParticles[0]; freeParticles.RemoveAt(0); } else { particle = new Particle(); } // Emit new particle float fRand1 = ((float)rand.Next(int.MaxValue) / (float)int.MaxValue) * (float)Math.PI * 2.0f; float fRand2 = ((float)rand.Next(int.MaxValue) / (float)int.MaxValue) * (float)Math.PI * 2.0f; particle.isSpark = false; particle.initialPosition = vPosition + new Vector3(0.0f, radius, 0.0f); particle.initialVelocity.X = (float)Math.Cos(fRand1) * (float)Math.Sin(fRand2) * 100f; particle.initialVelocity.Z = (float)Math.Sin(fRand1) * (float)Math.Sin(fRand2) * 100f; particle.initialVelocity.Y = (float)Math.Cos(fRand2) * 100f; particle.positionVector = particle.initialPosition; particle.velocityVector = particle.initialVelocity; particle.diffuseColor = Color.Violet; particle.fadeColor = Color.Black; particle.fadeProgression = 1.0f; particle.creationTime = time; particlesList.Add(particle); particles++; } }
internal SoapParameters(XmlMembersMapping request, XmlMembersMapping response, string[] parameterOrder, CodeIdentifiers identifiers) { ArrayList requestList = new ArrayList(); ArrayList responseList = new ArrayList(); AddMappings(requestList, request); if (response != null) AddMappings(responseList, response); if (parameterOrder != null) { for (int i = 0; i < parameterOrder.Length; i++) { string elementName = parameterOrder[i]; XmlMemberMapping requestMapping = FindMapping(requestList, elementName); SoapParameter parameter = new SoapParameter(); if (requestMapping != null) { if (RemoveByRefMapping(responseList, requestMapping)) parameter.codeFlags = CodeFlags.IsByRef; parameter.mapping = requestMapping; requestList.Remove(requestMapping); AddParameter(parameter); } else { XmlMemberMapping responseMapping = FindMapping(responseList, elementName); if (responseMapping != null) { parameter.codeFlags = CodeFlags.IsOut; parameter.mapping = responseMapping; responseList.Remove(responseMapping); AddParameter(parameter); } } } } foreach (XmlMemberMapping requestMapping in requestList) { SoapParameter parameter = new SoapParameter(); if (RemoveByRefMapping(responseList, requestMapping)) parameter.codeFlags = CodeFlags.IsByRef; parameter.mapping = requestMapping; AddParameter(parameter); } if (responseList.Count > 0) { if (!((XmlMemberMapping) responseList[0]).CheckSpecified) { ret = (XmlMemberMapping)responseList[0]; responseList.RemoveAt(0); } foreach (XmlMemberMapping responseMapping in responseList) { SoapParameter parameter = new SoapParameter(); parameter.mapping = responseMapping; parameter.codeFlags = CodeFlags.IsOut; AddParameter(parameter); } } foreach (SoapParameter parameter in parameters) { parameter.name = identifiers.MakeUnique(CodeIdentifier.MakeValid(parameter.mapping.MemberName)); } }
public void TestAddAndRemove() { StringBuilder sbl3 = new StringBuilder(99); StringBuilder sbl4 = new StringBuilder(99); int[] in4a = new int[9]; // Construct, and verify small capacity ArrayList al2 = new ArrayList(1); in4a[0] = al2.Capacity; Assert.Equal(1, in4a[0]); // Add the first obj sbl3.Length = 0; sbl3.Append("hi mom"); al2.Add(sbl3); sbl4 = (StringBuilder)al2[0]; Assert.Equal(sbl4.ToString(), sbl3.ToString()); // Add another obj, verify that Add auto increases Capacity when needed. sbl3.Length = 0; sbl3.Append("low dad"); al2.Add(sbl3); in4a[1] = al2.Capacity; Assert.True(in4a[1] > 1); Assert.True(in4a[1] > 1); sbl3 = (StringBuilder)al2[1]; Assert.Equal(sbl4.ToString(), sbl3.ToString()); // int p_inLoops0 = 2; int p_inLoops1 = 2; al2 = new ArrayList(); for (int aa = 0; aa < p_inLoops0; aa++) { al2.Capacity = 1; for (int bb = 0; bb < p_inLoops1; bb++) { al2.Add("aa==" + aa + " ,bb==" + bb); } while (al2.Count > 0) { al2.RemoveAt(0); } } Assert.Equal(0, al2.Count); }
public override void GetContextMenuEntries(Mobile from, ArrayList list) { base.GetContextMenuEntries( from, list ); for ( int i = 0; i < list.Count; ++i ) { if ( list[i] is ContextMenus.PaperdollEntry ) list.RemoveAt( i-- ); } }
public void RemoveUser(string strUser) { for (int i = 0; i < arrUsers.Count; i++) { if (arrUsers[i].ToString() == strUser) { arrUsers.RemoveAt(i); } } }
private void deleteButton_Click(object sender, EventArgs e) { int enteredValue = Convert.ToInt32(enterInputtextBox.Text); numbers.RemoveAt(enteredValue); foreach (int item in numbers) { OutputTextBox.Text = OutputTextBox.Text + item.ToString(); } }
public static ArrayList rest(ArrayList l) { ArrayList newList = new ArrayList(); foreach(object element in l) { newList.Add(element); } newList.RemoveAt(0); return newList; }
static void Main(string[] args) { // Array Console.WriteLine("Create an Array type collection of Animal objects and use it:"); Animal[] animalArray = new Animal[2]; // Strongly typed Cow myCow1 = new Cow("Deirdre"); animalArray[0] = myCow1; animalArray[1] = new Chicken("Ken"); foreach (Animal myAnimal in animalArray) { Console.WriteLine("New {0} object added to Array collection, " + "Name = {1}", myAnimal.ToString(), myAnimal.Name); } Console.WriteLine("Array collection {0} objects.", animalArray.Length); animalArray[0].Feed(); // invoke Animal method directly ((Chicken)animalArray[1]).LayEgg(); // cast to Chicken to invoke subclass method Console.WriteLine(); // ArrayList Console.WriteLine("Create an ArrayList type collection of Animal " + "objects and se it:"); ArrayList animalArrayList = new ArrayList(); // A collection of System.Objects Cow myCow2 = new Cow("Hayley"); animalArrayList.Add(myCow2); animalArrayList.Add(new Chicken("Row")); foreach (Animal myAnimal in animalArrayList) { Console.WriteLine("New {0} object added to ArrayList collection," + " Name = {1}", myAnimal.ToString(), myAnimal.Name); } Console.WriteLine("ArrayList collection contains {0} objects.", animalArrayList.Count); ((Animal)animalArrayList[0]).Feed(); // cast to Animal ((Chicken)animalArrayList[1]).LayEgg(); // cast to Chicken to invoke subclass method Console.WriteLine(); // Additional ArrayList manipulation Console.WriteLine("Additional manipulation of ArrayList:"); animalArrayList.RemoveAt(0); ((Animal)animalArrayList[0]).Feed(); animalArrayList.AddRange(animalArray); ((Chicken)animalArrayList[2]).LayEgg(); Console.WriteLine("The animal called {0} is at index {1}.", myCow1.Name, animalArrayList.IndexOf(myCow1)); myCow1.Name = "Janice"; Console.WriteLine("The animal is now called {0}.", ((Animal)animalArrayList[1]).Name); Console.ReadKey(); }
public void RemoveOverlay(ScreenOverlay overlay) { for (int i = 0; i < overlays.Count; i++) { ScreenOverlay curOverlay = (ScreenOverlay)overlays[i]; if (curOverlay.IconImagePath == overlay.IconImagePath && overlay.Name == curOverlay.Name) { overlays.RemoveAt(i); } } }
private ArrayList Loop(ref ArrayList inArray) { var subList = new ArrayList { inArray[0] }; inArray.RemoveAt(0); int i = 0; while( i < inArray.Count) { if ((int)inArray[i] > (int)subList[subList.Count-1]) { subList.Add(inArray[i]); inArray.RemoveAt(i); } else i++; } return subList; }
public static void FilterOutFixedWidthConnections(ArrayList connList) { for (int i = connList.Count - 1; i >= 0; i--) { ConnectionManager connManager = connList[i] as ConnectionManager; if (string.Compare("Delimited", (string)connManager.Properties["Format"].GetValue(connManager)) != 0) { connList.RemoveAt(i); } } }
private string DetermineLocalizedUrl() { ArrayList localeParts = new ArrayList(Page.UserCulture.Name.Split('-')); while (localeParts.Count > 0 && !FileExists(localeParts)) { localeParts.RemoveAt(localeParts.Count - 1); } string locale = String.Join("-", (string[]) localeParts.ToArray(typeof(string))); return Page.ImagesRoot + (locale.Length > 0 ? "/" + locale : "") + "/" + this.ImageName; }
public void RemoveParent(wfActivity obj) { for (int i = 0; i < Parents.Count; i++) { actRule rule = (actRule)Parents[i]; if (rule.Node == obj) { rule.Node = null; Parents.RemoveAt(i); } } }
public void RemoveChild(wfActivity obj) { for (int i = 0; i < Childs.Count; i++) { actRule rule = (actRule)Childs[i]; if (rule.Node == obj) { rule.Node = null; Childs.RemoveAt(i); } } }
public Boolean resetBoard(int move) { if ((move & 0x88) != 0) { Console.WriteLine("Invalid reset move!"); } board[move] = 0; numPieces -= 1; maxTurn = !maxTurn; moveList.RemoveAt(moveList.Count - 1); return(true); }
static public int RemoveAt(IntPtr l) { try { System.Collections.ArrayList self = (System.Collections.ArrayList)checkSelf(l); System.Int32 a1; checkType(l, 2, out a1); self.RemoveAt(a1); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static int RemoveAt(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); System.Collections.ArrayList obj = (System.Collections.ArrayList)ToLua.CheckObject(L, 1, typeof(System.Collections.ArrayList)); int arg0 = (int)LuaDLL.luaL_checknumber(L, 2); obj.RemoveAt(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static void Main(string[] args) { System.Collections.ArrayList a = new System.Collections.ArrayList(); Random r = new Random(); PrintValues(a); for (int i = 0; i < 10; i++) { a.Add(r.Next(100)); } PrintValues(a); a.Sort(); PrintValues(a); a.RemoveAt(3); PrintValues(a); }
public string ReceiveMessage(string strUser) { string strMess = string.Empty; for (int i = 0; i < arrMessage.Count; i++) { string[] strTo = arrMessage[i].ToString().Split(':'); if (strTo[0].ToString() == strUser) { for (int j = 1; j < strTo.Length; j++) { strMess = strMess + strTo[j] + ":"; } arrMessage.RemoveAt(i); break; } } return(strMess); }
public void Dispose() { // Haupt-Thread beenden if (mainThread != null) { mainThread.Abort(); } // Client-Threads beenden if (Clients.Count > 0) { for (int cnt = Clients.Count - 1; cnt >= 0; cnt--) { ServerInstance srv = (ServerInstance)Clients[cnt]; srv.serverThread.Abort(); Clients.RemoveAt(cnt); } } // Event-Handler abmelden //status.messageEvents=null; }
//Since we can not guarantee the order or the exact time that the event handler is called //We wil look for an event that was firered that matches the type and that bytesToRead //is greater then the parameter public void Validate(SerialData eventType, int bytesToRead) { lock (this) { for (int i = 0; i < EventType.Count; i++) { if (eventType == (SerialData)EventType[i] && bytesToRead <= (int)BytesToRead[i] && (SerialPort)Source[i] == com) { EventType.RemoveAt(i); BytesToRead.RemoveAt(i); Source.RemoveAt(i); NumEventsHandled--; return; } } } Assert.True(false, $"Validate {eventType} failed"); }
/// <summary> /// Remove a drawable object. /// Note that axes are not updated. /// </summary> /// <param name="p">Drawable to remove.</param> /// <param name="updateAxes">if true, the axes are updated.</param> public void Remove(IDrawable p, bool updateAxes) { int index = drawables_.IndexOf(p); if (index < 0) { return; } drawables_.RemoveAt(index); xAxisPositions_.RemoveAt(index); yAxisPositions_.RemoveAt(index); zPositions_.RemoveAt(index); if (updateAxes) { UpdateAxes(true); } RefreshZOrdering(); }
private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { e.Graphics.FillRectangle(Brushes.White, panel1.ClientRectangle); if (movingStuff.Count < maxStuff) { if (movingStuff.Count == 0) { movingStuff.Add(stuffWidth * -1); } else { int lastThing = Int32.MaxValue; foreach (int thing in movingStuff) { lastThing = Math.Min(thing, lastThing); } if (lastThing >= stuffWidth) { movingStuff.Add(stuffWidth * -1); } } } foreach (int thing in movingStuff) { e.Graphics.FillEllipse( Brushes.Blue, thing, (panel1.ClientRectangle.Height / 2) - (stuffWidth / 2), stuffWidth, stuffWidth); } for (int i = movingStuff.Count - 1; i > -1; i--) { movingStuff[i] = marqueeStep + (int)movingStuff[i]; if (((int)movingStuff[i]) > panel1.ClientRectangle.Right) { movingStuff.RemoveAt(i); } } }
private int nextInt(System.IO.StreamReader fr) { for (;;) { if (line.Count == 0) { string buf = fr.ReadLine(); if (buf == null) { GLPK.glp_cli_error("End of file reached"); } line.AddRange(buf.Split(' ')); } string token = (string)line [0]; token = token.Trim(); line.RemoveAt(0); if (token.Length > 0) { return(Convert.ToInt32(token)); } } }
//Since we can not garantee the order or the exact time that the event handler is called //We wil look for an event that was firered that matches the type and that bytesToRead //is greater then the parameter public bool Validate(SerialError eventType, int bytesToRead) { bool retValue = false; lock (this) { for (int i = 0; i < EventType.Count; i++) { if (eventType == (SerialError)EventType[i] && bytesToRead <= (int)BytesToRead[i] && (SerialPort)Source[i] == _com) { EventType.RemoveAt(i); BytesToRead.RemoveAt(i); Source.RemoveAt(i); NumEventsHandled--; retValue = true; break; } } } return(retValue); }
private void vHistoryNew(string strCommand) { if (strCommand != "") { // Verificando se eh igual ao ultimo if (m_arlHistory.Count > 0) { if (strCommand != m_arlHistory[m_arlHistory.Count - 1].ToString()) { m_arlHistory.Add(strCommand); } } else { m_arlHistory.Add(strCommand); } // Removendo se existir mais do que X Historicos while (m_arlHistory.Count > MAX_HISTORY) { m_arlHistory.RemoveAt(0); } } m_nIdHistory = m_arlHistory.Count - 1; }
/// <summary> Remove the given sequence number from the list of seqnos eligible /// for retransmission. If there are no more seqno intervals in the /// respective entry, cancel the entry from the retransmission /// scheduler and remove it from the pending entries /// </summary> public virtual void remove(long seqno) { lock (msgs.SyncRoot) { for (int index = 0; index < msgs.Count; index++) { RetransmitterEntry e = (RetransmitterEntry)msgs[index]; lock (e) { if (seqno < e.low || seqno > e.high) { continue; } e.remove(seqno); if (e.low > e.high) { e.cancel(); msgs.RemoveAt(index); } } break; } } }
//--------------------------------------------------------------------- public static string RunEstimate(System.Collections.ArrayList Exp) { try { int k = 0, a, b, res; while (Exp.Count > 1) { if (!(("*".Equals(Exp[k])) || ("/".Equals(Exp[k])) || ("+".Equals(Exp[k])) || (("-".Equals(Exp[k])) || ("mod".Equals(Exp[k]))))) { if ("m".Equals(Exp[k]) || ("p".Equals(Exp[k]))) { a = int.Parse(Exp[k - 1].ToString()); if ("p".Equals(Exp[k])) { res = a; } else { res = int.Parse(MathLibrary.IABS(a).ToString()); if (MathLibrary._lastError.Length > 0) { ShowMessege = true; expression = MathLibrary._lastError; return(expression); } } Exp.RemoveAt(k); Exp.RemoveAt(k - 1); Exp.Insert(k - 1, res.ToString()); k -= 1; } k++; } else { try { a = int.Parse(Exp[k - 2].ToString()); b = int.Parse(Exp[k - 1].ToString()); } catch { ShowMessege = true; expression = "error 06"; return(expression); } switch (Exp[k].ToString()) { case "+": res = MathLibrary.Add(a, b); if (MathLibrary._lastError.Length > 0) { ShowMessege = true; expression = MathLibrary._lastError; MathLibrary._lastError = ""; return(expression); } break; case "-": res = MathLibrary.Sub(a, b); if (MathLibrary._lastError.Length > 0) { ShowMessege = true; expression = MathLibrary._lastError; MathLibrary._lastError = ""; return(expression); } break; case "*": res = MathLibrary.Mult(a, b); if (MathLibrary._lastError.Length > 0) { ShowMessege = true; expression = MathLibrary._lastError; MathLibrary._lastError = ""; return(expression); } break; case "/": res = MathLibrary.Div(a, b); if (MathLibrary._lastError.Length > 0) { ShowMessege = true; expression = MathLibrary._lastError; MathLibrary._lastError = ""; return(expression); } break; case "mod": res = MathLibrary.Mod(a, b); if (MathLibrary._lastError.Length > 0) { ShowMessege = true; expression = MathLibrary._lastError; MathLibrary._lastError = ""; return(expression); } break; default: ShowMessege = true; expression = "error 03"; return(expression); } Exp.RemoveAt(k); Exp.RemoveAt(k - 1); Exp.RemoveAt(k - 2); Exp.Insert(k - 2, res.ToString()); k -= 2; } } return(Exp[0].ToString()); } catch { ShowMessege = true; expression = "error 03"; return(expression); } }
//----------------------------------------------------------------------------------------------------- public static System.Collections.ArrayList CreateStack() { try { String[] Exp = expression.Split(' '); System.Collections.ArrayList FinalStack = new System.Collections.ArrayList(); System.Collections.ArrayList Stack = new System.Collections.ArrayList(); int cur = 0; while (cur < Exp.Length) { bool b1 = false; int b = -1; // якщо число 0-9 for (int i = 0; i < 10; i++) { if (Exp[cur][0].ToString() == i.ToString()) { b1 = true; break; } } if (b1) { FinalStack.Add(Exp[cur].ToString()); cur++; continue; } if ((Exp[cur].ToString() == "m") || (Exp[cur].ToString() == "p")) { Stack.Add(Exp[cur].ToString()); cur++; continue; } // Якщо "+" "-" if ((Exp[cur] == "+") || (Exp[cur] == "-")) { if (Stack.Count > 0) { if (Stack[Stack.Count - 1].ToString() != "(") { b = 2; } else { b = 1; } } else { b = 1; } } //якщо *, /, мод if ((Exp[cur] == "*") || (Exp[cur] == "/") || (Exp[cur] == "mod")) { if (Stack.Count > 0) { if (!((Stack[Stack.Count - 1].ToString() == "(") || (Stack[Stack.Count - 1].ToString() == "+") || (Stack[Stack.Count - 1].ToString() == "-"))) { b = 3; } else { b = 1; } } else { b = 1; } } if ((Exp[cur] == "(")) { b = 1; } if ((Exp[cur] == ")")) { b = 4; } //---------------------- switch (b) { case 1: Stack.Add(Exp[cur]); cur++; break; case 2: b1 = false; while (!b1) { FinalStack.Add(Stack[Stack.Count - 1]); Stack.RemoveAt(Stack.Count - 1); if (Stack.Count > 0) { if (Stack[Stack.Count - 1].ToString() == "(") { Stack.Add(Exp[cur]); cur++; b1 = true; } } else { Stack.Add(Exp[cur]); cur++; b1 = true; } } break; case 3: b1 = false; while (!b1) { FinalStack.Add(Stack[Stack.Count - 1]); Stack.RemoveAt(Stack.Count - 1); if (Stack.Count > 0) { if ((Stack[Stack.Count - 1].ToString() == "(") || (Stack[Stack.Count - 1].ToString() == "+") || (Stack[Stack.Count - 1].ToString() == "-")) { Stack.Add(Exp[cur]); cur++; b1 = true; } } else { Stack.Add(Exp[cur]); cur++; b1 = true; } } break; case 4: b1 = false; while (!b1) { FinalStack.Add(Stack[Stack.Count - 1]); Stack.RemoveAt(Stack.Count - 1); if (Stack[Stack.Count - 1].ToString() == "(") { Stack.RemoveAt(Stack.Count - 1); cur++; b1 = true; } } break; default: FinalStack.Clear(); Stack.Clear(); ShowMessege = true; cur = Exp.Length; FinalStack.Add("error 03"); break; } } while (Stack.Count > 0) { FinalStack.Add(Stack[Stack.Count - 1]); Stack.RemoveAt(Stack.Count - 1); } System.Collections.ArrayList MyStack = new System.Collections.ArrayList(expression.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); MyStack = FinalStack; return(MyStack); } catch { System.Collections.ArrayList FinalStack = new System.Collections.ArrayList(); ShowMessege = true; FinalStack.Add("error 03"); return(FinalStack); } }
static void Main(string[] args) { /* ArrayList类删除元素的四种方法: * 1、ArrayList(变量名).Remove(值); * 2、ArrayList(变量名).RemoveAt(索引值) * 3、ArrayList(变量名).RemoveRange(开始索引值,需要删除的元素个数) * 4、ArrayList(变量名).Clear() //q清除所有元素 */ //ArrayList.Remove() System.Collections.ArrayList MyArrayList = new System.Collections.ArrayList(); string[] MyStringArray = { "张三", "李四", "王五", "赵六" }; MyArrayList.AddRange(MyStringArray); MyArrayList.Add(3.14); MyArrayList.Add(2298); MyArrayList.Add('A'); //第一遍未进行删除 - 遍历数组 foreach (object MyEach in MyArrayList) { Console.WriteLine(MyEach); } Console.WriteLine("============分割条==========="); //删除元素 MyArrayList.Remove("张三"); //第二遍进行删除元素后 - 遍历数组 foreach (object MyEach in MyArrayList) { Console.WriteLine(MyEach); } Console.WriteLine("============分割条==========="); //ArrayList(变量名).RemoveAt(索引值) //删除元素 MyArrayList.RemoveAt(0); //第三遍进行删除元素后 - 遍历数组 foreach (object MyEach in MyArrayList) { Console.WriteLine(MyEach); } Console.WriteLine("============分割条==========="); //ArrayList(变量名).RemoveRange(开始索引值,需要删除的元素个数) //删除元素 MyArrayList.RemoveRange(0, 2); //第四遍进行删除元素后 - 遍历数组 foreach (object MyEach in MyArrayList) { Console.WriteLine(MyEach); } Console.WriteLine("============分割条==========="); //ArrayList(变量名).RemoveRange(开始索引值,需要删除的元素个数) //删除所有元素 MyArrayList.Clear(); //第五遍进行删除元素后 - 遍历数组 foreach (object MyEach in MyArrayList) { Console.WriteLine(MyEach); } Console.ReadKey(); }
/// <seealso cref="org._3pq.jgrapht.traverse.CrossComponentIterator.provideNextVertex()"> /// </seealso> protected internal override System.Object provideNextVertex() { System.Object tempObject = m_queue[0]; m_queue.RemoveAt(0); return(tempObject); }
public void RemoveAt(int index) { m_Entries.RemoveAt(index); m_Owner.ViewRefresh(); }
/// <summary> /// Updates the scene /// </summary> public void Update(float fSecsPerFrame, int NumParticlesToEmit, System.Drawing.Color clrEmitColor, System.Drawing.Color clrFadeColor, float fEmitVel, Vector3 vPosition) { time += fSecsPerFrame; //Console.WriteLine(time.ToString()); //if (time < .1) // return; m_loc = vPosition; for (int ii = particlesList.Count - 1; ii >= 0; ii--) { Particle p = (Particle)particlesList[ii]; // Calculate new position //float fT = time - p.creationTime; float fT = time - p.creationTime; p.fadeProgression -= fSecsPerFrame * 0.60f; p.positionVector = p.initialVelocity * fT + p.initialPosition; p.velocityVector.Z = 0; if (p.fadeProgression < 0.0f) { p.fadeProgression = 0.0f; } // Kill old particles if (p.fadeProgression <= 0.0f) { // Kill particle freeParticles.Add(p); particlesList.RemoveAt(ii); if (!p.isSpark) { particles--; } } else { particlesList[ii] = p; } } // Emit new particles int particlesEmit = particles + NumParticlesToEmit; while (particles < particlesLimit && particles < particlesEmit) { Particle particle; if (freeParticles.Count > 0) { particle = (Particle)freeParticles[0]; freeParticles.RemoveAt(0); } else { particle = new Particle(); } // Emit new particle float fRand1 = ((float)rand.Next(int.MaxValue) / (float)int.MaxValue) * (float)Math.PI * 1.0f; float fRand2 = ((float)rand.Next(int.MaxValue) / (float)int.MaxValue) * (float)Math.PI * 0.25f; particle.isSpark = false; particle.initialPosition = vPosition + offset; particle.initialVelocity.X = (float)Math.Cos(fRand1) * (float)Math.Sin(fRand2) * .5f; particle.initialVelocity.Y = (float)Math.Sin(fRand1) * (float)Math.Sin(fRand2) * .5f; particle.initialVelocity.Z = (float)Math.Cos(fRand2); particle.positionVector = particle.initialPosition; particle.velocityVector = particle.initialVelocity; particle.diffuseColor = clrEmitColor; particle.fadeColor = clrFadeColor; particle.fadeProgression = 1.0f; particle.creationTime = time; particlesList.Add(particle); particles++; } }
public void RemoveAt(int index) { a.RemoveAt(index); }