SetRange() public méthode

public SetRange ( int index, ICollection c ) : void
index int
c ICollection
Résultat void
Exemple #1
0
 static int SetRange(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         System.Collections.ArrayList obj = (System.Collections.ArrayList)ToLua.CheckObject(L, 1, typeof(System.Collections.ArrayList));
         int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
         System.Collections.ICollection arg1 = (System.Collections.ICollection)ToLua.CheckObject(L, 3, typeof(System.Collections.ICollection));
         obj.SetRange(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
 static public int SetRange(IntPtr l)
 {
     try {
         System.Collections.ArrayList self = (System.Collections.ArrayList)checkSelf(l);
         System.Int32 a1;
         checkType(l, 2, out a1);
         System.Collections.ICollection a2;
         checkType(l, 3, out a2);
         self.SetRange(a1, a2);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemple #3
0
		public void SetRange_Overflow ()
		{
			ArrayList al = new ArrayList ();
			al.Add (this);
			al.SetRange (Int32.MaxValue, new ArrayList ());
		}
Exemple #4
0
		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");
			}
		}
Exemple #5
0
        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);

            
        }
        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();
        }