本文整理汇总了C#中System.Collections.ArrayList.RemoveRange方法的典型用法代码示例。如果您正苦于以下问题:C# ArrayList.RemoveRange方法的具体用法?C# ArrayList.RemoveRange怎么用?C# ArrayList.RemoveRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.ArrayList
的用法示例。
在下文中一共展示了ArrayList.RemoveRange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ContactListBuilder
public ContactListBuilder(ArrayList fullContactRegistry)
{
var boundsDetector = new ContactBoundsDetector();
while(boundsDetector.NextBoundary(fullContactRegistry) > 0)
{
ArrayList contactDetails = new ArrayList();
int boundary = boundsDetector.NextBoundary(fullContactRegistry);
if (boundary > fullContactRegistry.Count)
{
contacts.Add(new Contact(fullContactRegistry));
return;
}
for (int i=0; i<boundary; i++)
{
contactDetails.Add(fullContactRegistry[i]);
}
contacts.Add(new Contact(contactDetails));
fullContactRegistry.RemoveRange(0, boundary);
}
}
示例2: 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());
}
}
示例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: 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);
}
示例5: Breaker
private string Breaker(ArrayList Cell_String)
{
for (int i = 1; i < Cell_String.Count; i++)
{
if (Fun_Class.IsFunction(Cell_String[i].ToString()))
{
int found = 1;
int start = i + 1;
while (found != 0)
{
start++;
if (Cell_String[start].ToString().Equals("("))
found++;
if (Cell_String[start].ToString().Equals(")"))
found--;
}
ArrayList atemp = new ArrayList(Cell_String.GetRange(i, start - i + 1));
Cell_String.RemoveRange(i, start - i + 1);
Cell_String.Insert(i, Breaker(atemp));
}
}
//PrintArrayList(Cell_String);
//System.Console.WriteLine(Cell_String[0].ToString());
return Fun_Class.CallFunction(Cell_String);
}
示例6: FilterResultsInInterval
public void FilterResultsInInterval(DateTime Start, DateTime End, ArrayList List)
{
if (List == null)
return;
if (List.Count < 2)
return;
List.Sort();
List.RemoveRange(1, List.Count-1);
}
示例7: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
linkeo linker = new linkeo();
ArrayList campos = new ArrayList();
ArrayList datos = new ArrayList();
string resultado;
int id;
//especifico campos
campos.Add("descripcion, ");
campos.Add("unidad_medida, ");
campos.Add("racion_unidad_medida, ");
campos.Add("comentario ");
//recolecto datos
datos.Add(" ' ");
datos.Add(this.TextBox1.Text);//des
datos.Add(" ' ");
datos.Add(" , ");
datos.Add(this.DropDownList1.SelectedValue);//um
datos.Add(" , ");
datos.Add(this.TextBox2.Text);//ra um
datos.Add(" , ");
datos.Add(" ' ");
datos.Add(this.TextBox5.Text);//com
datos.Add(" ' ");
resultado = linker.insercion_de_dataset("productos", campos, datos);
Label1.Text = resultado;
id = linker.obtener_id("productos");
campos.RemoveRange(0, campos.Count);
datos.RemoveRange(0, datos.Count);
//especifico campos
campos.Add("cantidad, ");
campos.Add("indice_repo, ");
campos.Add("comentario, ");
campos.Add("id_producto ");
//recolecto datos
datos.Add(this.TextBox3.Text);//des
datos.Add(" , ");
datos.Add(this.TextBox4.Text);//um
datos.Add(" , ");
datos.Add(" ' ");
datos.Add("stock inicial");//ra um
datos.Add(" ' ");
datos.Add(" , ");
datos.Add(id);
resultado = linker.insercion_de_dataset("stock", campos, datos);
Label2.Text = resultado;
}
示例8: Main
static void Main(string[] args)
{
ArrayList al = new ArrayList();
al.Add("Paris");
al.Add("Ottowa");
al.AddRange(new string[] { "Rome", "Tokyo", "Tunis", "Canberra" });
Console.WriteLine("Count: {0}", al.Count);
Console.WriteLine("Capacity: {0}", al.Capacity);
Console.WriteLine("Print values using foreach");
PrintValues(al);
Console.WriteLine("Print values using IEnumerator");
PrintValuesByEnumerator(al);
// Get second item in list as string
string str = (string)al[1]; // need to cast, would also unbox if stored type was value type
Console.WriteLine("al[1] = {0}", str);
// Get first three items
ArrayList firstThree = al.GetRange(0, 3);
PrintValues(firstThree);
// Remove next two
al.RemoveRange(3, 2);
PrintValues(al);
// Get, insert and remove
object itemOne = al[1];
al.Insert(1, "Moscow");
al.RemoveAt(2);
PrintValues(al);
// Sort
al.Sort();
PrintValues(al);
// Search
int targetIndex = al.BinarySearch("Moscow");
Console.WriteLine("Index of Moscow: {0}", targetIndex);
// Trim capacity
al.TrimToSize();
Console.WriteLine("Count: {0}", al.Count);
Console.WriteLine("Capacity: {0}", al.Capacity);
// Creates a new ArrayList with five elements and initialize each element with a value.
ArrayList al2 = ArrayList.Repeat("Boston", 5); // static method
PrintValues(al2);
}
示例9: Combine
public override Pair<IList, bool> Combine(IList oldh, IList newh) {
ArrayList result = new ArrayList();
result.AddRange(oldh);
foreach(object newit in newh) {
if(!result.Contains(newit)) {
result.Add(newit);
}
}
result.Sort(GetComparer());
bool done = result.Count >= Max;
if( done ) {
result.RemoveRange(Max, result.Count - Max);
}
return new Pair<IList,bool>(result, done);
}
示例10: CollapsPushActions
/// <summary>
/// Collaps sequence of single push actions into one multiple-push action
/// </summary>
private void CollapsPushActions(ArrayList actionRecord) {
int i = 0;
bool isPush;
while (i<(actionRecord.Count-1)) {
isPush = actionRecord[i] is ActionPush;
if (isPush) {
int j = i;
int count = 1;
do {
i++;
if (i<actionRecord.Count) {
isPush=(actionRecord[i] is ActionPush);
if (isPush) count++;
}
} while ((isPush)&&(i<actionRecord.Count));
if (count>1) {
ActionPush[] pushList = new ActionPush[count];
actionRecord.CopyTo(j,pushList,0,count);
actionRecord.RemoveRange(j,count);
ActionPushList pl = new ActionPushList(pushList);
actionRecord.Insert(j,pl);
i=j+1;
}
} else {
// recursively step through functions inner actions
ActionDefineFunction f = actionRecord[i] as ActionDefineFunction;
if (f!=null) CollapsPushActions(f.ActionRecord);
// and function2 of course
ActionDefineFunction2 f2 = actionRecord[i] as ActionDefineFunction2;
if (f2!=null) CollapsPushActions(f2.ActionRecord);
i++;
}
}
}
示例11: tailString
public static string tailString(string toTail, int lines)
{
string[] textArray = toTail.Split('\n');
ArrayList textList = new ArrayList(textArray);
string returnText = "";
if (textList.Count > lines)
{
textList.RemoveRange(0, (textList.Count - lines));
textArray = (string[])textList.ToArray(typeof(string));
returnText = String.Join("\n", textArray);
}
else
{
returnText = toTail;
}
return returnText;
}
示例12: BindDropdowns
public void BindDropdowns(string[] headerItems)
{
try
{
ArrayList headers = new ArrayList();
headers.AddRange(headerItems);
headers.RemoveRange(headers.Count - 20, 20);
for (int i = 0; i < GridFieldmap.Rows.Count; i++)
{
TableTextFields.Clear();
TableTextFields.AddRange(headers);
DropDownList ddlContactMasterFields = (DropDownList)this.GridFieldmap.Rows[i].FindControl("ddlContactMasterFields");
Label headerText = (Label)this.GridFieldmap.Rows[i].FindControl("lblHeaderField");
ddlContactMasterFields.Items.Clear();
ddlContactMasterFields.Items.Add(new ListItem("--Select--", "--Select--"));
ddlContactMasterFields.DataSource = TableTextFields;
ddlContactMasterFields.DataBind();
DataTable dtfields = AdvanceManageFieldBase.SelectCustomFields(ConnectionString);
dtfields.AsEnumerable().ToList().ForEach(delegate(DataRow drRow) { ddlContactMasterFields.Items.Add(new ListItem(drRow["FieldName"].ToString(), drRow["ContactFieldName"].ToString())); });
string clmName = headerText.Text.Replace(" ", string.Empty);
if (clmName == "Email")
clmName = "EmailAddress";
else if (clmName == "ResponseChannel")
clmName = "DirectMailPaper";
ListItem mapItem = ddlContactMasterFields.Items.FindByText(clmName);
if (mapItem != null)
ddlContactMasterFields.Items.FindByText(mapItem.Text).Selected = true;
else
{
ddlContactMasterFields.SelectedIndex = 0;
LinkButton lbtnRemove = (LinkButton)GridFieldmap.Rows[i].FindControl("lbtnRemoveMapping");
lbtnRemove.Enabled = false;
lbtnRemove.Attributes.Add("style", "text-decoration:none;");
}
}
updatePanelFieldmap.Update();
}
catch (Exception ex)
{
throw ex;
}
}
示例13: ArrayLists
public ArrayLists()
{
ArrayList arryList1 = new ArrayList();
//add() to add individual at the end of data
arryList1.Add(1);
arryList1.Add("Two");
arryList1.Add(3);
arryList1.Add(4.5);
ArrayList arryList2 = new ArrayList();
arryList2.Add(100);
arryList2.Add(200);
//adding an entire collection
ArrayList arrylist = new ArrayList();
arrylist.AddRange(arryList2);
//access individual
var firstElement = (int) arryList1[0];
var secondElement = (string) arryList1[1];
var thirdElement = (int) arryList1[2];
var forthElement = (float) arryList1[3];
//accesss using loop
foreach (var val in arryList1)
{
Console.WriteLine(val);
}
for (int i = 0; i < arryList1.Count; i++)
{
Console.WriteLine(arryList1[i]);
}
//remove item using index
arryList1.RemoveAt(2); //remove value two
arryList1.RemoveRange(0,2); //remove two elements starting from 1st item (0 index)
}
示例14: Main
static void Main(string[] args)
{
var arrayLst = new ArrayList();
arrayLst.Add(1);
PrintArrayList(arrayLst);
arrayLst.AddRange(new[] { 2, 3, 7, 6, 5, 4 });
PrintArrayList(arrayLst);
arrayLst.Insert(index: 0, value: 0);
PrintArrayList(arrayLst);
arrayLst.RemoveAt(index: 4);
PrintArrayList(arrayLst);
arrayLst.Remove(obj: 1);
PrintArrayList(arrayLst);
arrayLst.RemoveRange(index: 2, count: 3);
PrintArrayList(arrayLst);
arrayLst.Reverse();
PrintArrayList(arrayLst);
arrayLst.Sort();
PrintArrayList(arrayLst);
bool hasTwo = arrayLst.Contains(2);
Console.WriteLine(hasTwo);
int two = (int)arrayLst[1];
Console.WriteLine(two);
Console.ReadLine();
}
示例15: Reduce
internal static String Reduce(String path)
{
// ignore query string
String queryString = null;
if (path != null)
{
int iqs = path.IndexOf('?');
if (iqs >= 0)
{
queryString = path.Substring(iqs);
path = path.Substring(0, iqs);
}
}
int length = path.Length;
int examine;
// Make sure we don't have any back slashes
path = path.Replace('\\', '/');
// quickly rule out situations in which there are no . or ..
for (examine = 0; ; examine++)
{
examine = path.IndexOf('.', examine);
if (examine < 0)
{
return (queryString != null) ? (path + queryString) : path;
}
if ((examine == 0 || path[examine - 1] == '/')
&& (examine + 1 == length || path[examine + 1] == '/' ||
(path[examine + 1] == '.' && (examine + 2 == length || path[examine + 2] == '/'))))
{
break;
}
}
// OK, we found a . or .. so process it:
ArrayList list = new ArrayList();
StringBuilder sb = new StringBuilder();
int start;
examine = 0;
for (;;)
{
start = examine;
examine = path.IndexOf('/', start + 1);
if (examine < 0)
{
examine = length;
}
if (examine - start <= 3 &&
(examine < 1 || path[examine - 1] == '.') &&
(start + 1 >= length || path[start + 1] == '.'))
{
if (examine - start == 3)
{
if (list.Count == 0)
{
throw new Exception(SR.GetString(SR.UrlPath_CannotExitUpTopDirectory));
}
sb.Length = (int)list[list.Count - 1];
list.RemoveRange(list.Count - 1, 1);
}
}
else
{
list.Add(sb.Length);
sb.Append(path, start, examine - start);
}
if (examine == length)
{
break;
}
}
return sb.ToString() + queryString;
}