private char[] Read_char_int_int(SerialPort com) { System.Collections.ArrayList receivedChars = new System.Collections.ArrayList(); char[] buffer = new char[DEFAULT_READ_CHAR_ARRAY_SIZE]; int totalCharsRead = 0; int numChars; while (true) { try { numChars = com.Read(buffer, 0, buffer.Length); } catch (TimeoutException) { break; } receivedChars.InsertRange(totalCharsRead, buffer); totalCharsRead += numChars; } if (totalCharsRead < receivedChars.Count) { receivedChars.RemoveRange(totalCharsRead, receivedChars.Count - totalCharsRead); } return((char[])receivedChars.ToArray(typeof(char))); }
private char[] Read_byte_int_int(SerialPort com) { System.Collections.ArrayList receivedBytes = new System.Collections.ArrayList(); byte[] buffer = new byte[DEFAULT_READ_BYTE_ARRAY_SIZE]; int totalBytesRead = 0; int numBytes; while (true) { try { numBytes = com.Read(buffer, 0, buffer.Length); } catch (TimeoutException) { break; } receivedBytes.InsertRange(totalBytesRead, buffer); totalBytesRead += numBytes; } if (totalBytesRead < receivedBytes.Count) { receivedBytes.RemoveRange(totalBytesRead, receivedBytes.Count - totalBytesRead); } return(com.Encoding.GetChars((byte[])receivedBytes.ToArray(typeof(byte)))); }
static void Main(string[] args) { System.Collections.ArrayList a = new System.Collections.ArrayList(); a.Add("Welcome"); a.Add(100); a.Add(true); a.Add(22.2); a.Add("Non generic collection"); Console.WriteLine("ArrayList Count :" + a.Count); Console.WriteLine("ArrayList Capacity :" + a.Capacity); System.Collections.ArrayList b = new System.Collections.ArrayList(); a.AddRange(b); // add arraylist b to a // add range will add in th end // insert elements into arraylist a.Insert(0, "Hello"); a.Insert(3, 555); System.Collections.ArrayList c = new System.Collections.ArrayList(); a.InsertRange(2, c); // inserting c aaraylist to 2 position in a //insert range will insert in middle Console.WriteLine("ArrayList Count :" + a.Count); Console.WriteLine("ArrayList Capacity :" + a.Capacity); Console.WriteLine("*********ArrayList Elements******"); foreach (var item in a) { Console.WriteLine(item); } string msg = (string)a[0]; //access elements based on index float v = (float)a[2]; Console.WriteLine("Element at 0 is :" + msg); Console.WriteLine("Element at 2 is :" + v); // Removing an element which is having a value 20.5f a.Remove(20.2f); // Removing an element at index 0 a.RemoveAt(0); // Removing 2 elements starting from index 3 a.RemoveRange(3, 2); Console.ReadKey(); }
/*******************************/ /// <summary> /// Sets the capacity for the specified ArrayList /// </summary> /// <param name="vector">The ArrayList which capacity will be set</param> /// <param name="newCapacity">The new capacity value</param> public static void SetCapacity(System.Collections.ArrayList vector, int newCapacity) { if (newCapacity > vector.Count) { vector.AddRange(new Array[newCapacity - vector.Count]); } else if (newCapacity < vector.Count) { vector.RemoveRange(newCapacity, vector.Count - newCapacity); } vector.Capacity = newCapacity; }
static void Main(string[] args) { //元素删除有四种方法 System.Collections.ArrayList myArrayList = new System.Collections.ArrayList(3); myArrayList.Add(1); myArrayList.Add("成功"); myArrayList.Add(25.63); string[] mystringArray = { "张三", "李四", "王五", "赵六" }; myArrayList.AddRange(mystringArray); Console.WriteLine("删除之前的内容"); foreach (object outelemnet in myArrayList) { Console.Write(outelemnet + "\t"); } //Remove(值) Console.WriteLine("\n删除之后的内容为:"); myArrayList.Remove("张三"); foreach (object outelemnet in myArrayList) { Console.Write(outelemnet + "\t"); } //RemoveAt(索引值) Console.WriteLine("\n删除 李四 之后的内容为"); myArrayList.RemoveAt(3); foreach (object outelemnet in myArrayList) { Console.Write(outelemnet + "\t"); } //RemoveRange(起始索引,删除个数) Console.WriteLine("\n 删除 王五 赵六 之后的内容为"); myArrayList.RemoveRange(3, 2); foreach (object outelement in myArrayList) { Console.Write(outelement + "\t"); } //Clear() Console.WriteLine("\n清除所有元素"); myArrayList.Clear(); foreach (object outelement in myArrayList) { Console.Write(outelement + "\t"); } Console.ReadKey(); }
Formula[] FormulaArrayCreator.CreateArray(int count) { System.Collections.ArrayList list = new System.Collections.ArrayList(); GenerateFormulaArray(list); RandomScramblingList(list); // 缩减长度 if (count < list.Count) { list.RemoveRange(count, list.Count - count); } return((Formula[])list.ToArray(typeof(Formula))); }
/*Sync up deferred consumption */ protected internal virtual void syncConsume() { if (numToConsume > 0) { if (nMarkers > 0) { // guess mode -- leave leading characters and bump offset. markerOffset += numToConsume; } else { // normal mode -- remove "consumed" characters from buffer queue.RemoveRange(0, numToConsume); } numToConsume = 0; } }
public void RemoveRange(int index, int count) { arr.RemoveRange(index, count); }
private string copyAuraTo(string charTypeFileName, string[] distSplit) { string results = ""; System.Collections.ArrayList sourceArrayList = new System.Collections.ArrayList(); System.Collections.ArrayList distArrayList = new System.Collections.ArrayList(); COH_CostumeUpdater.common.COH_IO.fillList(sourceArrayList, filePath); COH_CostumeUpdater.common.COH_IO.fillList(distArrayList, charTypeFileName); int srcAurasStartIndx = sourceArrayList.IndexOf("\tDisplayName \"Auras\""); int srcAurasEndIndx = sourceArrayList.IndexOf("End", srcAurasStartIndx); int distAurasStartIndx = distArrayList.IndexOf("\tDisplayName \"Auras\""); int distAurasEndIndx = distArrayList.IndexOf("End", distAurasStartIndx); distArrayList.RemoveRange(distAurasStartIndx + 1, distAurasEndIndx - distAurasStartIndx - 1); string aurasType = ""; if (distSplit.Length == 3) {//"Arachnos Female Soldier", aurasType += distSplit[1]; } else { aurasType += distSplit[0]; } for (int i = srcAurasStartIndx + 1, k = 1; i < srcAurasEndIndx; i++, k++) { string aurasPath = (string)sourceArrayList[i]; string aurasNewPath = aurasPath.Replace("Male", aurasType); if (aurasPath.Contains(@"Male")) { //\tInclude Menu\Costume\Common\Auras\Female\AuraNone.ctm string src = pathRoot + aurasPath.Substring("\tInclude ".Length); string dist = pathRoot + aurasNewPath.Substring("\tInclude ".Length); if (!File.Exists(dist) && File.Exists(src)) { File.Copy(src, dist); fixFXDistPath(dist, aurasType); results += "Copied \"" + src + "\" to \"" + dist + "\"\r\n"; } } distArrayList.Insert(distAurasStartIndx + k, aurasNewPath); } FileInfo fi = new FileInfo(charTypeFileName); if (fi.IsReadOnly) { //COH_CostumeUpdater.assetsMangement.CohAssetMang.preFileCheckout(charTypeFileName); COH_CostumeUpdater.assetsMangement.CohAssetMang.checkout(charTypeFileName);//.checkoutNoEdit(charTypeFileName); //COH_CostumeUpdater.assetsMangement.CohAssetMang.postFileCheckout(charTypeFileName); } results += COH_CostumeUpdater.common.COH_IO.writeDistFile(distArrayList, charTypeFileName); return(results); }