本文整理汇总了C#中System.Collections.ArrayList.GetRange方法的典型用法代码示例。如果您正苦于以下问题:C# ArrayList.GetRange方法的具体用法?C# ArrayList.GetRange怎么用?C# ArrayList.GetRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.ArrayList
的用法示例。
在下文中一共展示了ArrayList.GetRange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: Sort
public ArrayList Sort(ArrayList inArray)
{
if (1 == inArray.Count)
return inArray;
int middle = inArray.Count >> 1;
ArrayList left = Sort(inArray.GetRange(0, middle));
ArrayList right = Sort(inArray.GetRange(middle, inArray.Count - middle));
return Merge(left, right);
}
示例3: 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);
}
示例4: TestGetItems
public void TestGetItems()
{
//--------------------------------------------------------------------------
// Variable definitions.
//--------------------------------------------------------------------------
ArrayList arrList = null;
//
// Construct array list.
//
arrList = new ArrayList();
// Add items to the lists.
for (int ii = 0; ii < strHeroes.Length; ++ii)
{
arrList.Add(strHeroes[ii]);
}
// Verify items added to list.
Assert.Equal(strHeroes.Length, arrList.Count);
//Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of
//BinarySearch, Following variable cotains each one of these types of array lists
ArrayList[] arrayListTypes = {
(ArrayList)arrList.Clone(),
(ArrayList)ArrayList.Adapter(arrList).Clone(),
(ArrayList)ArrayList.FixedSize(arrList).Clone(),
(ArrayList)ArrayList.ReadOnly(arrList).Clone(),
(ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
(ArrayList)ArrayList.Synchronized(arrList).Clone()};
foreach (ArrayList arrayListType in arrayListTypes)
{
arrList = arrayListType;
//
// [] Verify get method.
//
// Search and verify selected items.
for (int ii = 0; ii < strHeroes.Length; ++ii)
{
// Verify get.
Assert.Equal(0, ((string)arrList[ii]).CompareTo(strHeroes[ii]));
}
//
// [] Invalid Index.
//
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
string str = (string)arrList[(int)arrList.Count];
});
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
string str = (string)arrList[-1];
});
}
}
示例5: select
public override ArrayList select(ArrayList gens)
{
int nr;
if (gens.Count >= this._newPopSize)
nr = (int)(gens.Count * this._newPopSize);
else
nr = 1;
gens.Sort((IComparer)new GenomeComparer());
return gens.GetRange(0, nr);
}
示例6: Recombine
public ArrayList Recombine(ArrayList maleGenes, ArrayList femaleGenes)
{
double maleConstraint = random.NextDouble();
int maleCount = (int)Math.Ceiling(maleGenes.Count * maleConstraint);
int femaleCount = (int)Math.Floor(femaleGenes.Count * (1-maleConstraint));
ArrayList child = new ArrayList(maleCount + femaleCount);
child.InsertRange(0, maleGenes.GetRange(0, maleCount));
child.InsertRange(maleCount, femaleGenes.GetRange(femaleGenes.Count - femaleCount, femaleCount));
for (int i = 0; i < child.Count; i++)
child[i] = (child[i] as IGene).Clone();
return child;
}
示例7: 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);
}
示例8: Join
/// <summary>
/// Joins a new string with the elements of the array.
/// </summary>
/// <param name="joiner">The joiner.</param>
/// <param name="joinees">The joinees.</param>
/// <returns>The combined string.</returns>
public static string Join(string joiner, ArrayList joinees)
{
if (joinees.Count == 0)
{
return string.Empty;
}
string joined = (string)joinees[0];
foreach (string str in joinees.GetRange(1, joinees.Count - 1))
{
joined = joined + joiner + str;
}
return joined;
}
示例9: Recombine
public ArrayList Recombine(ArrayList maleGenes, ArrayList femaleGenes)
{
if (maleGenes.Count != femaleGenes.Count)
throw new GenesIncompatibleException();
ArrayList child = new ArrayList(maleGenes.Count);
int middle = maleGenes.Count / 2;
child.InsertRange(0, maleGenes.GetRange(0, middle).Clone() as ArrayList);
child.InsertRange(middle, femaleGenes.GetRange(middle, femaleGenes.Count - middle).Clone() as ArrayList);
// Create Deep Copy
for (int i = 0; i < child.Count; i++)
child[i] = (child[i] as IGene).Clone();
return child;
}
示例10: addToListBox
private void addToListBox(ArrayList list)
{
try
{
int rango = list.Count - posListBox * 10;
if (rango > 10)
rango = 10;
foreach (Frases item in list.GetRange(posListBox * 10, rango))
{
lbFrases.Items.Add(item.Autor + ": \t" + item.Frase);
}
}
catch { }
}
示例11: Merge
public static ArrayList Merge(ArrayList left, ArrayList right)
{
var result = new ArrayList();
int leftptr=0, rightptr=0;
while (leftptr < left.Count && rightptr < right.Count)
result.Add((int) left[leftptr] < (int) right[rightptr] ? left[leftptr++] : right[rightptr++]);
if (leftptr < left.Count)
result.AddRange(left.GetRange(leftptr, left.Count - leftptr));
if (rightptr < right.Count)
result.AddRange(right.GetRange(rightptr, right.Count - rightptr));
return result;
}
示例12: Main
static void Main(string[] args)
{
//Create an ArrayList and add two ints
ArrayList list = new ArrayList();
list.Add("bird");
list.Add("rock");
list.Add("jacket");
list.Add("shoe");
// Get Last two elements in ArrayList
ArrayList range = list.GetRange(2, 2);
//Display Elements
foreach (string value in range)
{
Console.WriteLine(value); // jacket, shoe
}
}
示例13: TestArrayListWrappers
public void TestArrayListWrappers()
{
ArrayList alst1;
string strValue;
Array arr1;
//[] Vanila test case - ToArray returns an array of this. We will not extensively test this method as
// this is a thin wrapper on Array.Copy which is extensively tested elsewhere
alst1 = new ArrayList();
for (int i = 0; i < 10; i++)
{
strValue = "String_" + i;
alst1.Add(strValue);
}
ArrayList[] arrayListTypes = {
alst1,
ArrayList.Adapter(alst1),
ArrayList.FixedSize(alst1),
alst1.GetRange(0, alst1.Count),
ArrayList.ReadOnly(alst1),
ArrayList.Synchronized(alst1)};
foreach (ArrayList arrayListType in arrayListTypes)
{
alst1 = arrayListType;
arr1 = alst1.ToArray(typeof(string));
for (int i = 0; i < 10; i++)
{
strValue = "String_" + i;
Assert.Equal(strValue, (string)arr1.GetValue(i));
}
//[] this should be covered in Array.Copy, but lets do it for
Assert.Throws<InvalidCastException>(() => { arr1 = alst1.ToArray(typeof(int)); });
Assert.Throws<ArgumentNullException>(() => { arr1 = alst1.ToArray(null); });
}
//[]lets try an empty list
alst1.Clear();
arr1 = alst1.ToArray(typeof(Object));
Assert.Equal(0, arr1.Length);
}
示例14: Destruct
public static AESInfo Destruct(String message, String privateKey)
{
int ebs = RSAKeySize/8;
AESInfo result = new AESInfo();
ArrayList bytes = new ArrayList(Convert.FromBase64String(StripMessage(message)));
byte[] keyPart = (byte[]) bytes.GetRange(0, ebs).ToArray(Type.GetType("System.Byte"));
result.key = RSADecrypt(keyPart, privateKey);
result.IV = RSADecrypt((byte[]) bytes.GetRange(ebs, ebs).ToArray(Type.GetType("System.Byte")), privateKey);
result.message = (byte[]) bytes.GetRange(ebs*2, bytes.Count - ebs*2).ToArray(Type.GetType("System.Byte"));
return result;
}
示例15: GetTrainPersonImages
private void GetTrainPersonImages(string trainPersonName)
{
string strFile = m_rootPath + trainPersonName+"\\info.txt";
try
{
if (File.Exists(strFile))
{
using (StreamReader sr = new StreamReader(strFile, Encoding.GetEncoding("gb2312")))
{
ArrayList str_list = new ArrayList();
while (sr.Peek() >= 0)
{
string str = sr.ReadLine();
str = m_rootPath + trainPersonName + "\\"+str;
str_list.Add(str);
}
int count = str_list.Count;
m_trainPersonImagesInfo = str_list.GetRange(3, count - 3);
}
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}