本文整理汇总了C#中System.Collections.ArrayList.SetRange方法的典型用法代码示例。如果您正苦于以下问题:C# ArrayList.SetRange方法的具体用法?C# ArrayList.SetRange怎么用?C# ArrayList.SetRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.ArrayList
的用法示例。
在下文中一共展示了ArrayList.SetRange方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetRange_Overflow
public void SetRange_Overflow ()
{
ArrayList al = new ArrayList ();
al.Add (this);
al.SetRange (Int32.MaxValue, new ArrayList ());
}
示例2: Main
static void Main(string[] args)
{
var a = new ArrayList();
a.Add(234);
a.Add(234);
a.Add(4444444);
a.Add(234);
a.Add(2341234);
a.RemoveAt(0);
a.Remove(4444444);
Display(a);
a[0] = DateTime.Now.AddMonths(-1);
Display(a);
int count = a.Count;
int idx = a.IndexOf(234);
a.Insert(2, 999999);
Display(a);
bool b = a.Contains(999999);
a.Reverse(0, a.Count);
Display(a);
var mas = a.ToArray();
a.SetRange(0, new [] {1, 3, 2, 3});
Display(a);
var s = new Stack();
s.Push(22);
s.Push(33);
s.Push(44);
Display(s);
var x = s.Pop();
Display(s);
var q = new Queue();
q.Enqueue(111);
q.Enqueue(222);
q.Enqueue(333);
Display(q);
var e = q.Dequeue();
Display(q);
}
示例3: TestSetRange
public void TestSetRange ()
{
{
bool errorThrown = false;
try {
char [] c = { 'a', 'b', 'c' };
ArrayList al1 =
ArrayList.ReadOnly (new ArrayList (3));
al1.SetRange (0, c);
} catch (NotSupportedException) {
errorThrown = true;
} catch (Exception e) {
Assert.Fail ("Incorrect exception thrown at 1: " + e.ToString ());
}
Assert.IsTrue (errorThrown, "setrange on read only error not thrown");
}
{
bool errorThrown = false;
try {
ArrayList al1 = new ArrayList (3);
al1.SetRange (0, null);
} catch (ArgumentNullException) {
errorThrown = true;
} catch (ArgumentOutOfRangeException) {
errorThrown = true;
} catch (Exception e) {
Assert.Fail ("Incorrect exception thrown at 2: " + e.ToString ());
}
Assert.IsTrue (errorThrown, "setrange with null error not thrown");
}
{
bool errorThrown = false;
try {
char [] c = { 'a', 'b', 'c' };
ArrayList al1 = new ArrayList (3);
al1.SetRange (-1, c);
} catch (ArgumentOutOfRangeException) {
errorThrown = true;
} catch (Exception e) {
Assert.Fail ("Incorrect exception thrown at 3: " + e.ToString ());
}
Assert.IsTrue (errorThrown, "setrange with negative index error not thrown");
}
{
bool errorThrown = false;
try {
char [] c = { 'a', 'b', 'c' };
ArrayList al1 = new ArrayList (3);
al1.SetRange (2, c);
} catch (ArgumentOutOfRangeException) {
errorThrown = true;
} catch (Exception e) {
Assert.Fail ("Incorrect exception thrown at 4: " + e.ToString ());
}
Assert.IsTrue (errorThrown, "setrange with too much error not thrown");
}
{
char [] c = { 'a', 'b', 'c' };
ArrayList al1 = ArrayList.Repeat ('?', 3);
Assert.IsTrue (c [0] != (char) al1 [0], "no match yet");
Assert.IsTrue (c [1] != (char) al1 [1], "no match yet");
Assert.IsTrue (c [2] != (char) al1 [2], "no match yet");
al1.SetRange (0, c);
Assert.AreEqual (c [0], al1 [0], "should match");
Assert.AreEqual (c [1], al1 [1], "should match");
Assert.AreEqual (c [2], al1 [2], "should match");
}
}
示例4: Spell
public Element?[] Spell(string word, SearchAlgorithm algorithm)
{
Dictionary<int, Element> indexed = new Dictionary<int, Element>();
word = Regex.Replace(word.ToLower(), "[^a-z\\s]", "");
switch (algorithm)
{
case SearchAlgorithm.ElementBased:
foreach (Element element in elements)
{
string symbol = element.Symbol.ToLower();
if (word.Contains(symbol))
{
foreach (int i in word.IndexOfAll(symbol))
indexed.Add(i, element);
word = word.Replace(symbol, new string ('_', symbol.Length));
}
}
break;
case SearchAlgorithm.ChunkSearch:
int maxElementLength = elements.Max(e => e.Symbol.Length);
for (int searchLength = maxElementLength; searchLength > 0; searchLength--)
{
Element[] currentElements = elements.Where(e => e.Symbol.Length == searchLength).ToArray();
for (int x = 0; x < word.Length - searchLength + 1; x++)
foreach(Element currentElement in currentElements)
if (word.Substring(x, searchLength) == currentElement.Symbol.ToLower())
{
indexed.Add(x, currentElement);
ArrayList tmpList = new ArrayList(((ICollection)(Array)word.ToCharArray()));
tmpList.SetRange(x, (ICollection)(Array)new string('_', searchLength).ToCharArray());
word = new string(Array.ConvertAll(tmpList.ToArray(), item => (char)item));
}
}
break;
}
List<Element?> spelled = new List<Element?>();
int max = indexed.Max(item => item.Key);
Element value;
for (int i = 0; i <= max; i++)
{
if (indexed.TryGetValue(i, out value))
spelled.Add(value);
else if (word[i] == ' ')
spelled.Add(null);
}
return spelled.ToArray();
}