当前位置: 首页>>代码示例>>C#>>正文


C# SortedList.GetKey方法代码示例

本文整理汇总了C#中SortedList.GetKey方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.GetKey方法的具体用法?C# SortedList.GetKey怎么用?C# SortedList.GetKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SortedList的用法示例。


在下文中一共展示了SortedList.GetKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: runTest

 public virtual bool runTest()
 {
     Console.Error.WriteLine( "Co4324ctor_dictionary  runTest() started." );
     String strLoc="Loc_000oo";
     StringBuilder sblMsg = new StringBuilder( 99 );
     int iCountErrors = 0;
     int iCountTestcases = 0;
     SortedList sl2 = null;
     Hashtable ht = null;
     StringBuilder sbl3 = new StringBuilder( 99 );
     StringBuilder sbl4 = new StringBuilder( 99 );
     StringBuilder sblWork1 = new StringBuilder( 99 );
     String str5 = null;
     String str6 = null;
     String str7 = null;
     int[] in4a = new int[9];
     int nCapacity = 100;
     try
     {
     LABEL_860_GENERAL:
         do
         {
             strLoc="100cc";
             iCountTestcases++;
             ht = new Hashtable();
             Co4324ctor_dictionary k0 = new Co4324ctor_dictionary ("cde");
             Co4324ctor_dictionary k1 = new Co4324ctor_dictionary ("abc");
             Co4324ctor_dictionary k2 = new Co4324ctor_dictionary ("bcd");
             ht.Add (k0, null);
             ht.Add (k1, null);
             ht.Add (k2, null);
             iCountTestcases++;
             sl2 = new SortedList(ht);
             iCountTestcases++;
             if ( sl2 == null )
             {
                 Console.WriteLine( strTest+ "E_101" );
                 Console.WriteLine( strTest+ "SortedList creation failure" );
                 ++iCountErrors;
                 break;
             }
             iCountTestcases++;
             if ( sl2.Count  != 3 )
             {
                 Console.WriteLine( strTest+ "E_202" );
                 Console.WriteLine( strTest+ "New SortedList is not empty" );
                 ++iCountErrors;
             }
             iCountTestcases++;
             if (sl2.IndexOfKey(k0) != 2) 
             {
                 Console.Error.WriteLine(  "POINTTOBREAK: (E_12ys.1) IndexOfKey(k0)==" +
                     sl2.IndexOfKey(k0) );
                 ++iCountErrors;
             }
             iCountTestcases++;
             if (sl2.IndexOfKey(k1) != 0) 
             {
                 Console.Error.WriteLine( "POINTTOBREAK: (E_12ys.2) IndexOfKey(k1)=="
                     + sl2.IndexOfKey(k1) ) ;
                 ++iCountErrors;
             }
             iCountTestcases++;
             if (sl2.IndexOfKey(k2) != 1) 
             {
                 Console.Error.WriteLine( "POINTTOBREAK: (E_12ys.3) IndexOfKey(k2)=="
                     + sl2.IndexOfKey(k2) ) ;
                 ++iCountErrors;
             }
             iCountTestcases++;
             if ( !((Co4324ctor_dictionary)sl2.GetKey(0)).ToString().Equals ("abc"))
             {
                 Console.Error.WriteLine(  "POINTTOBREAK: (E_14dj.1) Equals(k0)=="
                     + ((Co4324ctor_dictionary)sl2.GetKey(0)).ToString().Equals ("abc") ) ;
                 ++iCountErrors;
             }
             iCountTestcases++;
             if ( !((Co4324ctor_dictionary)sl2.GetKey(1)).ToString().Equals ("bcd"))
             {
                 Console.Error.WriteLine( "POINTTOBREAK: (E_14dj.1) Equals(k1)=="
                     + ((Co4324ctor_dictionary)sl2.GetKey(1)).ToString().Equals ("bcd") ) ;
                 ++iCountErrors;
             }
             iCountTestcases++;
             if ( !((Co4324ctor_dictionary)sl2.GetKey(2)).ToString().Equals ("cde"))
             {
                 Console.Error.WriteLine(  "POINTTOBREAK: (E_14dj.1) Equals(k2)=="
                     + ((Co4324ctor_dictionary)sl2.GetKey(2)).ToString().Equals ("cde") ) ;
                 ++iCountErrors;
             }
             iCountTestcases++;
             ht = new Hashtable();
             sl2 = new SortedList(ht);
             if(sl2.Count!=0)
             {
                 ++iCountErrors;
                 Console.WriteLine("Err_3947tsg! wrong value returned");
             }
         } while ( false );
     }
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co4324ctor_dictionary.cs

示例2: runTest

 public virtual bool runTest()
 {
     Console.Error.WriteLine( "Co4348GetKey  runTest() started." );
     String strLoc="Loc_000oo";
     StringBuilder sblMsg = new StringBuilder( 99 );
     int iCountErrors = 0;
     int iCountTestcases = 0;
     SortedList sl2 = null;
     StringBuilder sbl3 = new StringBuilder( 99 );
     StringBuilder sbl4 = new StringBuilder( 99 );
     StringBuilder sblWork1 = new StringBuilder( 99 );
     String s1 = null;
     String s2 = null;
     int[] in4a = new int[9];
     int i = 0;
     try
     {
         do
         {
             strLoc="100cc";
             iCountTestcases++;
             sl2 = new SortedList( this );
             iCountTestcases++;
             if ( sl2 == null )
             {
                 Console.WriteLine( strTest+ "E_101" );
                 Console.WriteLine( strTest+ "SortedList creation failure" );
                 ++iCountErrors;
                 break;
             }
             iCountTestcases++;
             if ( sl2.Count  != 0 )
             {
                 Console.WriteLine( strTest+ "E_102" );
                 Console.WriteLine( strTest+ "New SortedList is not empty" );
                 ++iCountErrors;
             }
             strLoc="Loc_100aa";
             ++iCountTestcases;
             try 
             {
                 sl2.GetKey(0); 
                 ++iCountErrors;
                 sblMsg.Length =  0 ;
                 sblMsg.Append( "POINTTOBREAK: Error Err_2764! - must 've thrown ArgExc" );
                 Console.Error.WriteLine(  sblMsg.ToString()  );
             }
             catch (ArgumentException ) {}
             strLoc="Loc_110aa";
             ++iCountTestcases;
             try 
             {
                 sl2["first key"] = (String) null ; 
             }
             catch (ArgumentException ) 
             {
                 ++iCountErrors;
                 sblMsg.Length =  0 ;
                 sblMsg.Append( "POINTTOBREAK: Error Err_34fj! - must 've thrown ArgExc" );
                 Console.Error.WriteLine(  sblMsg.ToString()  );
             }
             ++iCountTestcases;
             if (sl2.Count  != 1) 
             {
                 ++iCountErrors;
                 sblMsg.Length =  0 ;
                 sblMsg.Append( "POINTTOBREAK: Error Err_60ff! - Count == " );
                 sblMsg.Append( sl2.Count  );
                 Console.Error.WriteLine(  sblMsg.ToString()  );
             }
             strLoc="Loc_120aa";
             ++iCountTestcases;
             sl2.Clear();
             strLoc="Loc_141aa";
             for (i=0; i<50; i++) 
             {
                 ++iCountTestcases;
                 sblMsg.Length =  0 ;
                 sblMsg.Append("key_");
                 sblMsg.Append(i);
                 s1 = sblMsg.ToString();
                 sblMsg.Length =  0 ;
                 sblMsg.Append("val_");
                 sblMsg.Append(i);
                 s2 = sblMsg.ToString();
                 sl2.Add (s1, s2);
             }
             strLoc="Loc_145aa";
             for (i=0; i<50; i++) 
             {
                 ++iCountTestcases;
                 ++iCountTestcases;
                 sblMsg.Length =  0 ;
                 sblMsg.Append("key_");
                 sblMsg.Append(i);
                 s1 = sblMsg.ToString();
                 if ( !((String)sl2.GetKey(sl2.IndexOfKey (s1))).Equals(s1))
                 {
                     ++iCountErrors;
                     sblMsg.Length =  0 ;
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co4348getkey.cs

示例3: runTest

 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     SortedList slst1;
     Int32 iNumberOfElements;
     String strValue;
     Array ar1;
     try 
     {
         do
         {
             strLoc = "Loc_001fn";
             iNumberOfElements = 10;
             slst1 = new SortedList(iNumberOfElements);
             for(int i=iNumberOfElements-1; i>=0;i--)
             {
                 slst1.Add(50 + i, "Value_" + i);
             }
             iCountTestcases++;
             if(slst1.Count!=iNumberOfElements) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_752dsg! Expected value not returned, " + slst1.Count + " " + iNumberOfElements);
             }
             for(int i=0; i<slst1.Count;i++)
             {
                 strValue = "Value_" + i;
                 if(!strValue.Equals(slst1[slst1.GetKey(i)])) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_000oo! Expected value not returned, " + strValue + " " + slst1[slst1.GetKey(i)]);
                 }
             }
             strLoc = "Loc_756tegd";
             try
             {
                 iCountTestcases++;
                 iNumberOfElements = -5;
                 slst1 = new SortedList(iNumberOfElements);
                 iCountErrors++;
                 Console.WriteLine("Err_7439dg! Exception not thrown");
             }
             catch(ArgumentOutOfRangeException)
             {
             }
             catch(Exception ex)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_097243sdgg! Unexpected exception thrown, " + ex);
             }
             strLoc = "Loc_74dsg";
             slst1 = new SortedList();
             strLoc = "Loc_175fdg";
             try
             {
                 iCountTestcases++;
                 slst1.Add(null, 5);
                 iCountErrors++;
                 Console.WriteLine("Err_7439dg! Exception not thrown");
             }
             catch(ArgumentNullException)
             {
             }
             catch(Exception ex)
             {
                 iCountErrors++;
                 Console.WriteLine("Err_0642efss! Unexpected exception thrown, " + ex);
             }
             iNumberOfElements = 10;
             slst1 = new SortedList();
             for(int i=iNumberOfElements-1; i>=0;i--)
             {
                 slst1.Add(i, null);
             }
             iCountTestcases++;
             for(int i=0; i<slst1.Count;i++)
             {
                 strValue = "Value_" + i;
                 if(slst1.GetByIndex(i)!=null) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_7620cdg! Expected value not returned, " + slst1.GetByIndex(i));
                 }
             }
             strLoc = "Loc_07534efsdgs";
             iNumberOfElements = 10;
             slst1 = new SortedList(iNumberOfElements);
             for(int i=iNumberOfElements-1; i>=0;i--)
             {
                 slst1.Add(50 + i, "Value_" + i);
             }
             iCountTestcases++;
             for(int i=0; i<slst1.Count;i++)
             {
                 strValue = "Value_" + i;
                 if(!slst1.Contains(50 + i)) 
                 {
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:co3953multimethods.cs

示例4: Main

    static void Main()
    {
        /* Write a program that finds the most frequent number in an array. Example:
         * {4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3}  4 (5 times) */

        Console.Write("Enter array lenght (or 0 for array autogeneration): ");
        int n = int.Parse(Console.ReadLine());
        int[] arr;
        if (n == 0)
        {
            // random generated array

            Random rnd = new Random();
            n = rnd.Next(20, 30);
            arr = new int[n];
            Console.WriteLine("Generated N is: {0}", n);
            Console.WriteLine("Generated array is:");
            for (int i = 0; i < n; i++)
            {
                arr[i] = rnd.Next(10);
                Console.Write("{0,2}", arr[i]);
            }
            Console.WriteLine();
        }
        else
        {
            // user defined and fileld array

            arr = new int[n];
            for (int i = 0; i < n; i++)
            {
                Console.Write("Element {0}: ", i + 1);
                arr[i] = int.Parse(Console.ReadLine());
            }
        }

        // input is done

        SortedList count = new SortedList(); // I use SortedList to automate some work. "Index" field is value of element, "value" element is count of this elements
        for (int i = 0; i < arr.Length; i++) // let's walk in array - form start to end
        {
            int index = count.IndexOfKey(arr[i]); // is this element already in sorted list?
            if (index < 0)
                count.Add(arr[i], 1); // no, this element is not in the list. Add them, and place "1" at count position
            else
                count[arr[i]] = (int)count[arr[i]]+1 ; // yes, element is in the list. Add 1 to count position.
        }

        //count of all elements is done

        int maxPos = 0; // now we must find which element have biggest count (in "value" fielt in sorted array)
        int maxValue = (int)count.GetByIndex(0); // get first element for starting
        for (int i = 1; i < count.Count; i++)
        {
            if (maxValue < (int)count.GetByIndex(i))
            {
                maxPos = i;
                maxValue = (int)count.GetByIndex(i);
            }
        }
        //finding the most frequent element is done

        Console.WriteLine("Value {0} is most frequent - {1} times",count.GetKey(maxPos),maxValue) ;
        for (int i = 0; i < n; i++)
        {
            if (arr[i] == (int)count.GetKey(maxPos))
                Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write("{0,2}", arr[i]);
            Console.ForegroundColor = ConsoleColor.Gray;
        }
        Console.WriteLine();
    }
开发者ID:TheOldMan66,项目名称:TelerikAcademy,代码行数:72,代码来源:MostFrequent.cs

示例5: DoIListTests

        private void DoIListTests(SortedList good, IList bad, Hashtable hsh1, DicType dic)
        {
            if (bad.IsReadOnly != good.IsReadOnly)
                hsh1["IsReadOnly"] = "";

            if (bad.IsFixedSize != good.IsFixedSize)
                hsh1["IsFixedSize"] = "";

            try
            {
                if (dic == DicType.Key)
                {
                    DoICollectionTests(good, bad, hsh1, DicType.Key);
                    for (int i = 0; i < good.Count; i++)
                    {
                        if (!bad.Contains(good.GetKey(i)))
                            hsh1["Contains"] = i;
                        if (bad[i] != good.GetKey(i))
                            hsh1["Item"] = "get";
                        if (bad.IndexOf(good.GetKey(i)) != i)
                            hsh1["IndexOf"] = i;
                    }
                    //we change the original and see if it is reflected in the IList
                    good.Add("ThisHasToBeThere", null);
                    if (!bad.Contains("ThisHasToBeThere"))
                        hsh1["Contains"] = "Modified";
                    if (bad.Count != bad.Count)
                        hsh1["Count"] = "Modified";
                }
                else if (dic == DicType.Value)
                {
                    DoICollectionTests(good, bad, hsh1, DicType.Value);
                    for (int i = 0; i < good.Count; i++)
                    {
                        if (!bad.Contains(good.GetByIndex(i)))
                            hsh1["Contains"] = i;
                        if (bad[i] != good.GetByIndex(i))
                            hsh1["Item"] = "get";
                        if (bad.IndexOf(good.GetByIndex(i)) != i)
                            hsh1["IndexOf"] = i;
                    }
                    //we change the original and see if it is reflected in the IList
                    good.Add("ThisHasToBeThere", "ValueWasJustAdded");
                    if (!bad.Contains(good["ThisHasToBeThere"]))
                        hsh1["Contains"] = "Modified";
                    if (bad.Count != bad.Count)
                        hsh1["Count"] = "Modified";
                }

                try
                {
                    bad.Add("AnyValue");
                    hsh1["Add"] = "No_Exception thrown";
                }
                catch (NotSupportedException)
                {
                }
                catch (Exception ex)
                {
                    hsh1["Add"] = ex.GetType().Name;
                }

                if (bad.Count != bad.Count)
                    hsh1["Count"] = "ReadWrite";

                try
                {
                    bad.Clear();
                    hsh1["Clear"] = "No_Exception thrown";
                }
                catch (NotSupportedException)
                {
                }
                catch (Exception ex)
                {
                    hsh1["Clear"] = ex.GetType().Name;
                }

                try
                {
                    bad.Insert(0, "AnyValue");
                    hsh1["Insert"] = "No_Exception thrown";
                }
                catch (NotSupportedException)
                {
                }
                catch (Exception ex)
                {
                    hsh1["Insert"] = ex.GetType().Name;
                }

                try
                {
                    bad.Remove("AnyValue");
                    hsh1["Remove"] = "No_Exception thrown";
                }
                catch (NotSupportedException)
                {
                }
                catch (Exception ex)
//.........这里部分代码省略.........
开发者ID:er0dr1guez,项目名称:corefx,代码行数:101,代码来源:WrapperTests.cs

示例6: SortListBox

    //------------------------------------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------------------------------------
    private void SortListBox(ref ListBox pList)
    {
        SortedList lListItems = new SortedList();

            if (pList.Items.Count <= 1)
                return;

            //add DropDownList items to SortedList
            foreach (ListItem lItem in pList.Items)
            {
                lListItems.Add(lItem.Text, lItem);
            }

            lListItems.TrimToSize();

            //clear DropDownList
            pList.Items.Clear();
            //add sorted items to listbox
            for (int i = 0; i < lListItems.Count; i++)
                pList.Items.Add((ListItem)lListItems[lListItems.GetKey(i)]);
    }
开发者ID:ssommerfeldt,项目名称:TAC_AH,代码行数:23,代码来源:SpeEmailForm.ascx.cs

示例7: CalculatePath

    private void CalculatePath()
    {
        //Debug.Log("Calculating...");

        navmesh = GameObject.Find("NavmeshGenerator").GetComponent<NavmeshSpawner>().GetNavmesh();
        path = new ArrayList();

        // cast rays up, down, left, right and if its longer than it should be, ignore the impact
        float expectedDist = navmesh.gameUnitStep + fudge;

        // Start the calculation by finding the closest node to the player (or GameObject to which we are attached)
        GameObject startPoint = FindClosestNavmeshPointTo(this.gameObject);
        Debug.Log ("Starting from: (" + startPoint.transform.position.x + ", " + startPoint.transform.position.y + ")");

        SearchElement startElement = new SearchElement(startPoint, 0.0f);

        // Then find the closest GameObject to the target
        endPoint = FindClosestNavmeshPointTo(target.gameObject);
        //Debug.Log ("Ending at: (" + endPoint.transform.position.x + ", " + endPoint.transform.position.y + ")");

        // Keep a priority queue of points on the frontier, sorted in increasing order by F = G + H
        // The CompareTo() function of each SearchElement takes into account the H value
        SortedList openSet = new SortedList();
        // Keep a list of NavmeshPoints we have already found in the SPT
        ArrayList closedSet = new ArrayList();

        openSet.Add(startElement, null);

        SearchElement finalSearchElement = null;

        while (openSet.Count > 0) {

            // Dequeue the element in the openSet with the smallest distance
            SearchElement current = openSet.GetKey(0) as SearchElement;

            // Is this what we are looking for?
            if (current.point == endPoint) {
                closedSet.Add(current.point);
                finalSearchElement = current;
                break;

            }

            // Remove this NavmeshPoint from the openSet and add it to the closedSet
            openSet.Remove(current);
            closedSet.Add(current.point);
            current.point.layer = 9;

            //Debug.Log ("Processing point at (" + current.point.transform.position.x
            //           + ", " + current.point.transform.position.y + ")");

            // Get all NavmeshPoints adjacent to this point in the form of SearchElements whose dists are current.dist
            // plus however long the edge from current to the adjacent point is (measured in terms of game space dist)
            ArrayList adj = GetAdjacentPoints(current, expectedDist);

            // Find out if any points adjacent to current are already in the openSet
            // If they are, find out if the distance through the current path is shorter than the distance
            // they are currently at through other paths. If the distance through current is shorter, update the dist
            // to be the dist through current, and update the from field to be current.

            // Note: We do not explicitly handle the heuristic estimate at this time, as it is taken care of for us
            // behind the scenes in the openSet.Add() function by the IComparable interface implemented by SearchElement
            foreach (SearchElement newFrontierElement in adj) {

                bool elementInOpenSet = false;
                bool replaceExistingElement = false;
                SearchElement existingElementIndex = null;

                foreach (SearchElement establishedFrontierElement in openSet.Keys) {
                    if (newFrontierElement.point == establishedFrontierElement.point) {

                        // This NavmeshPoint exists in the openSet
                        elementInOpenSet = true;

                        if (newFrontierElement.dist < establishedFrontierElement.dist) {

                            // The new path is a better path than the current path
                            replaceExistingElement = true;
                            existingElementIndex = establishedFrontierElement;
                        }

                        // Break out of the openSet for-loop; we are done here since we found a match
                        break;
                    }
                }

                if (!elementInOpenSet) {
                    openSet.Add(newFrontierElement, null);
                }
                else if (elementInOpenSet && replaceExistingElement) {
                    openSet.Remove(existingElementIndex);
                    openSet.Add(newFrontierElement, null);
                }

                foreach (SearchElement e in openSet.Keys) {
                    //Debug.Log("(" + e.point.transform.position.x + ", " + e.point.transform.position.y + "): "
                    //          + (e.dist + Vector2.Distance(e.point.transform.position, endPoint.transform.position)).ToString()
                    //          + "   ");
                }
            }
//.........这里部分代码省略.........
开发者ID:patriotpie,项目名称:AIProject_2,代码行数:101,代码来源:AStar.cs

示例8: TestCtorDefault

        public void TestCtorDefault()
        {
            StringBuilder sblMsg = new StringBuilder(99);

            SortedList sl2 = null;

            StringBuilder sbl3 = new StringBuilder(99);
            StringBuilder sbl4 = new StringBuilder(99);
            StringBuilder sblWork1 = new StringBuilder(99);

            //
            // 	Constructor: Create a default SortedList
            //
            sl2 = new SortedList();

            //  Verify that the SortedList is not null.
            Assert.NotNull(sl2);

            //  Verify that the SortedList is empty.
            Assert.Equal(0, sl2.Count);

            //
            // 	Constructor: few more tests
            //
            sl2 = new SortedList();

            var k0 = new CtorTestClass("cde");
            var k1 = new CtorTestClass("abc");
            var k2 = new CtorTestClass("bcd");

            sl2.Add(k0, null);
            sl2.Add(k1, null);
            sl2.Add(k2, null);

            //  Verify that the SortedList is not null.
            Assert.NotNull(sl2);

            //  Verify that the SortedList Count is right.
            Assert.Equal(3, sl2.Count);

            //  Verify that the SortedList actually sorted the hashtable.
            Assert.Equal(2, sl2.IndexOfKey(k0));

            Assert.Equal(0, sl2.IndexOfKey(k1));

            Assert.Equal(1, sl2.IndexOfKey(k2));

            //  Verify that the SortedList contains the right keys.

            Assert.True(((CtorTestClass)sl2.GetKey(0)).GetString().Equals("abc"));

            Assert.True(((CtorTestClass)sl2.GetKey(1)).GetString().Equals("bcd"));

            Assert.True(((CtorTestClass)sl2.GetKey(2)).GetString().Equals("cde"));
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:55,代码来源:CtorTests.cs

示例9: runTest


//.........这里部分代码省略.........
     table.Add("HH", "09");
     table.Add("HHH", "09");
     table.Add("HHHH", "09");
     table.Add("HHHHHHH", "09");
     table.Add("mm", "41");
     table.Add("mmm", "41");
     table.Add("mmmm", "41");
     table.Add("mmmmmmmmm", "41");
     table.Add("ss", "26");
     table.Add("sss", "26");
     table.Add("ssss", "26");
     table.Add("sssss", "26");
     table.Add("Lak", "Lak");
     table.Add(":", ":");
     table.Add(",", ",");
     table.Add("/", "/");
     table.Add("-", "-");
     table.Add(" ", " ");
     table.Add("~", "~");
     table.Add("   ", "   ");
     random = new Random();
     numberOfRounds = random.Next(100, 10000);
     formatString = String.Empty;expectedValue = String.Empty;
     for(int i=0; i<numberOfRounds; i++){
     returnedValue=String.Empty;
     try{
     numberOfStringConcats = random.Next(1, 20);
     builder1 = new StringBuilder();
     builder2 = new StringBuilder();
     previous = String.Empty;
     for(int j=0; j<numberOfStringConcats; j++){
     do{
     i1 = random.Next(table.Count);
     temp = (String)table.GetKey(i1);
     getOut = true;
     if(j!=0){
     if(temp.Length>previous.Length){
     if(temp.EndsWith(previous))
       getOut = false;
     }else{
     if(previous.EndsWith(temp))
       getOut = false;
     }
     }
     }while(!getOut);
     previous = temp;
     builder1.Append(temp);
     temp1 = (String)table.GetByIndex(i1);
     builder2.Append(temp1);
     if((String)table[temp] != temp1)
       throw new Exception("Loc_7432edgs! What is happening here? " + temp + " " + temp1);
     }
     formatString = builder1.ToString();
     if(formatString.Length==1){
     i--;
     continue;
     }
     expectedValue = builder2.ToString();
     returnedValue = date.ToString(formatString);
     if(!returnedValue.Equals(expectedValue)){
     iCountErrors++;
     Console.WriteLine("Err_87sdg! Format: {0}, Returned: {1}, Expected: {2}", formatString, returnedValue, expectedValue);
     }
     }catch(Exception){
     Console.WriteLine("Err_EDfdfd! Exception thrown, Format: {0}, Returned: {1}, Expected: {2}", formatString, returnedValue, expectedValue);					
     }
开发者ID:ArildF,项目名称:masters,代码行数:67,代码来源:co8573tostring_str.cs

示例10: findShortestPath

    public NavigationPath findShortestPath(GraphNode<StateConfig> start, GraphNode<StateConfig> goal)
    {
        SortedList open = new SortedList();
        HashSet<AStarNode> closed = new HashSet<AStarNode>();

        // Add the start node to the open list with its distance set to the distance
        // to the goal
        float startGoalDist = start.content.computeDistanceEuclidean(goal.content);
        open.Add(new AStarNode(start, null, 0, startGoalDist), startGoalDist);
        int iter = 0;
        while (open.Count != 0){
        //			foreach (DictionaryEntry item in open) {
        //				Debug.Log(item.Key);
        //			}

            // take off the front of the list, should be the node closest to the goal
            AStarNode front = open.GetKey(0) as AStarNode;
            //Debug.Log("Goal is " + goal);
            //Debug.Log("front is " + front.state);
            // Check if the front node is the goal, and return the path if it is.
            if (front.state.Equals(goal))
                return front.extractPath();

            open.RemoveAt(0);
            closed.Add(front);

            // Extract the list of neighbours from the front node
            List<GraphNode<StateConfig>> successors = front.state.neighbours;
            //Debug.Log("checking successors");
            foreach (var child in successors) {
            //	Debug.Log("Checking node " + child);
                bool inOpen = false;
                // Create new astarnode with the front node as the parent, and the pathcost
                // as the cost to the front plus the distance from the front to the child.
                // estimated cost temporarily set to zero, will be updated later if needed.
                AStarNode childNode = new AStarNode(child, front, front.pathCost + front.state.content.computeDistanceEuclidean(child.content), 0);
                AStarNode node;
            //	Debug.Log("Checking for this node in open list");
                foreach (DictionaryEntry entry in open) {
                    node = entry.Key as AStarNode;
            //		Debug.Log("Comparing " + childNode + " to " + node);
                    // Check the contents of the node and the child. If they
                    // are equal, the child is already in the open list
                    if (node.Equals(childNode)){
            //			Debug.Log("The two node states are equal");
                        // Cost of the identical node currently in the open list is
                        // larger than the cost of the current successor. We will replace
                        // the one currently in the open list with the new successor
                        if (node.pathCost > childNode.pathCost){
            //				Debug.Log("cost of node in open is larger than the one being examined, removing it");
                            open.Remove(node);
            //				Debug.Log("after removal open contains old node? " + open.ContainsKey(node));
                            // break so that we do not set inopen = true
                            break;
                        }
            //			Debug.Log("the path cost from the node already in the list is lower");
                        // The state is already in the open list and
                        // its path cost is lower than ours.
                        inOpen = true;
                        break;
                    }
                    //Debug.Log("Nodes not equal");
                }

                // Check if the node is already in the closed list
                bool inClosed = closed.Contains(childNode);
                //Debug.Log("Does the closed list contain the child node? " + inClosed);
                // If the node is not already in the closed or open lists (or perhaps
                // if it was in the open list but it had a higher path cost than the
                // current node) then add it to the open list, ordering by the estimated
                // cost to the goal.
                if (!inClosed && !inOpen){
                //	Debug.Log("Node is not in closed or open, so adding to the open list");
                    childNode.estCost = childNode.pathCost + childNode.state.content.computeDistanceEuclidean(goal.content);
                    try {
                        open.Add(childNode, childNode.estCost);
                    } catch (ArgumentException ex) {
                        // TODO: Sometimes we try to add nodes which are already in the open list. This
                        // hack works to prevent the error, and the search completes successfully,
                        // but there is a problem somewhere.
                        //Debug.Log("already in open");
                    }
                }
            }

        }

        return null;
    }
开发者ID:heuristicus,项目名称:DD2438,代码行数:89,代码来源:AStar.cs

示例11: VisitDocumentElements

        internal override void VisitDocumentElements(DocumentElements elements)
        {
#if true
            // New version without sorted list
            int count = elements.Count;
            for (int idx = 0; idx < count; ++idx)
            {
                Paragraph paragraph = elements[idx] as Paragraph;
                if (paragraph != null)
                {
                    Paragraph[] paragraphs = paragraph.SplitOnParaBreak();
                    if (paragraphs != null)
                    {
                        foreach (Paragraph para in paragraphs)
                        {
                            elements.InsertObject(idx++, para);
                            ++count;
                        }
                        elements.RemoveObjectAt(idx--);
                        --count;
                    }
                }
            }
#else
      SortedList splitParaList = new SortedList();

      for (int idx = 0; idx < elements.Count; ++idx)
      {
        Paragraph paragraph = elements[idx] as Paragraph;
        if (paragraph != null)
        {
          Paragraph[] paragraphs = paragraph.SplitOnParaBreak();
          if (paragraphs != null)
            splitParaList.Add(idx, paragraphs);
        }
      }

      int insertedObjects = 0;
      for (int idx = 0; idx < splitParaList.Count; ++idx)
      {
        int insertPosition = (int)splitParaList.GetKey(idx);
        Paragraph[] paragraphs = (Paragraph[])splitParaList.GetByIndex(idx);
        foreach (Paragraph paragraph in paragraphs)
        {
          elements.InsertObject(insertPosition + insertedObjects, paragraph);
          ++insertedObjects;
        }
        elements.RemoveObjectAt(insertPosition + insertedObjects);
        --insertedObjects;
      }
#endif
        }
开发者ID:Sl0vi,项目名称:MigraDoc,代码行数:52,代码来源:PdfFlattenVisitor.cs

示例12: Test01

        public void Test01()
        {
            SortedList slst1;
            Int32 iNumberOfElements;
            String strValue;
            Array ar1;

            // ctor(Int32)
            iNumberOfElements = 10;
            slst1 = new SortedList(iNumberOfElements);

            for (int i = iNumberOfElements - 1; i >= 0; i--)
            {
                slst1.Add(50 + i, "Value_" + i);
            }

            Assert.Equal(slst1.Count, iNumberOfElements);

            //we will assume that all the keys are sorted as the name implies. lets see
            //We intially filled this lit with descending and much higher keys. now we access the keys through index
            for (int i = 0; i < slst1.Count; i++)
            {
                strValue = "Value_" + i;
                Assert.Equal(strValue, slst1[slst1.GetKey(i)]);
            }

            //paramter stuff
            Assert.Throws<ArgumentOutOfRangeException>(() =>
                             {
                                 iNumberOfElements = -5;
                                 slst1 = new SortedList(iNumberOfElements);
                             }
            );

            slst1 = new SortedList();
            Assert.Throws<ArgumentNullException>(() =>
                             {
                                 slst1.Add(null, 5);
                             }
            );

            iNumberOfElements = 10;
            slst1 = new SortedList();

            for (int i = iNumberOfElements - 1; i >= 0; i--)
            {
                slst1.Add(i, null);
            }

            for (int i = 0; i < slst1.Count; i++)
            {
                strValue = "Value_" + i;
                Assert.Null(slst1.GetByIndex(i));
            }

            //Contains()
            iNumberOfElements = 10;
            slst1 = new SortedList(iNumberOfElements);
            for (int i = iNumberOfElements - 1; i >= 0; i--)
            {
                slst1.Add(50 + i, "Value_" + i);
            }

            for (int i = 0; i < slst1.Count; i++)
            {
                strValue = "Value_" + i;
                Assert.True(slst1.Contains(50 + i));
            }

            Assert.False(slst1.Contains(1));
            Assert.False(slst1.Contains(-1));

            //paramter stuff
            Assert.Throws<ArgumentNullException>(() =>
                             {
                                 slst1.Contains(null);
                             }
            );

            //get/set_Item
            slst1 = new SortedList();
            for (int i = iNumberOfElements - 1; i >= 0; i--)
            {
                slst1[50 + i] = "Value_" + i;
            }

            Assert.Equal(slst1.Count, iNumberOfElements);

            for (int i = 0; i < slst1.Count; i++)
            {
                strValue = "Value_" + i;
                Assert.Equal(strValue, slst1[i + 50]);
            }

            //already existent ones
            strValue = "Value_1";
            Assert.Equal(strValue, slst1[51]);

            strValue = "Different value";
            slst1[51] = strValue;
//.........这里部分代码省略.........
开发者ID:er0dr1guez,项目名称:corefx,代码行数:101,代码来源:MultiMethodsTests.cs

示例13: lbtnAddMealOption_Click

    /// <summary>
    /// This methods add meals value to list
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtnAddMealOption_Click(object sender, EventArgs e)
    {
        //if (txtMealOption.Text.Length > 0)
        //    lbMealOptions.Items.Add(txtMealOption.Text);
        //txtMealOption.Text = string.Empty;
        //lbMealOptions.Focus();

        SortedList objSortedList = new SortedList();
        int flg = 0;

        if (txtMealOption.Text.Length > 0)
        {
            foreach (ListItem lItem in lbMealOptions.Items)
            {
                if (txtMealOption.Text == lItem.Text)
                {
                    flg = 1;
                }
            }
            if (flg == 0)
            {
                lbMealOptions.Items.Add(txtMealOption.Text);
            }

            foreach (ListItem lItem in lbMealOptions.Items)
            {
                objSortedList.Add(lItem.Value, lItem);
            }

            lbMealOptions.Items.Clear();

            for (int i = 0; i < objSortedList.Count; i++)
            {
                lbMealOptions.Items.Add((ListItem)objSortedList[objSortedList.GetKey(i)]);
            }
        }
        txtMealOption.Text = string.Empty;
    }
开发者ID:rupendra-sharma07,项目名称:MainTrunk,代码行数:43,代码来源:ManageEvent.aspx.cs

示例14: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        string downloadDir = ConfigurationManager.AppSettings["downloadDir"];
        string html = GetDownloadDirectoryOutput(downloadDir);
        //string html = "<head><title>build.mutantdesign.co.uk - /builds/</title></head><body><H1>build.mutantdesign.co.uk - /builds/</H1><hr><pre><A HREF=\" / \">[To Parent Directory]</A><br><br>    Monday, November 21, 2005  8:33 PM      2251973 <A HREF=\"/builds/MbUnit-2.3.0.exe\">MbUnit-2.3.0.exe</A><br> Wednesday, November 23, 2005  9:36 AM      2251958 <A HREF=\"/builds/MbUnit-2.3.1.exe\">MbUnit-2.3.1.exe</A><br>    Monday, December 12, 2005  9:43 PM      2231225 <A HREF=\"/builds/MbUnit-2.3.11.exe\">MbUnit-2.3.11.exe</A><br> Wednesday, December 14, 2005 10:51 AM      2239306 <A HREF=\"/builds/MbUnit-2.3.13.exe\">MbUnit-2.3.13.exe</A><br>    Sunday, December 18, 2005  6:04 PM      2238969 <A HREF=\"/builds/MbUnit-2.3.15.exe\">MbUnit-2.3.15.exe</A><br>    Sunday, December 18, 2005  6:10 PM      2238976 <A HREF=\"/builds/MbUnit-2.3.16.exe\">MbUnit-2.3.16.exe</A><br>    Sunday, December 18, 2005  6:13 PM      2238980 <A HREF=\"/builds/MbUnit-2.3.17.exe\">MbUnit-2.3.17.exe</A><br>  Wednesday, January 04, 2006  1:49 AM      1294082 <A HREF=\"/builds/MbUnit-2.3.19.exe\">MbUnit-2.3.19.exe</A><br> Wednesday, November 23, 2005  9:53 AM      2251951 <A HREF=\"/builds/MbUnit-2.3.2.exe\">MbUnit-2.3.2.exe</A><br>   Thursday, January 19, 2006  2:59 PM      1294202 <A HREF=\"/builds/MbUnit-2.3.22.exe\">MbUnit-2.3.22.exe</A><br>     Friday, January 20, 2006  5:30 AM      1294179 <A HREF=\"/builds/MbUnit-2.3.23.exe\">MbUnit-2.3.23.exe</A><br></pre><hr></body>";

        if (html != string.Empty)
        {
            Regex regRelease = new Regex("HREF\\s*=\\s*(?:\"\"(?<1>[^\"\"]*)\"\"|(?<1>\\S+))");
            Regex regDate = new Regex("<br>(.*?)<A HREF");

            MatchCollection mclRelease = regRelease.Matches(html);
            MatchCollection mclDate = regDate.Matches(html);

            if (mclRelease.Count > 0 && mclDate.Count > 0)
            {
                SortedList list = new SortedList(new Comparer(System.Globalization.CultureInfo.CurrentCulture));
                StringBuilder strRelease = new StringBuilder();
                StringBuilder strDate = new StringBuilder();
                StringBuilder strDownload = new StringBuilder();

                int matchCount = 0;

                foreach (Match build in mclRelease)
                {
                    string releaseName = build.Value.Replace("HREF=\"", "").Trim();

                    if (releaseName.Length > 1 && releaseName != "/\">[To")
                    {
                        int i = releaseName.IndexOf("\">");
                        string release = releaseName.Substring(i + 2, releaseName.IndexOf("</A>") - i - 2);

                        string date = mclDate[matchCount].ToString();
                        date = date.Replace("<br>", "")
                                    .Replace("<A HREF", "");
                        date = date.Trim();

                        date = date.Substring(0, date.LastIndexOf(" "))
                                     .Trim();

                        DateTime trueDate = Convert.ToDateTime(date);

                        list.Add(release + " - Released " + trueDate, "<A href=\"" + downloadDir + "/" + release + "\">Download</A>");

                        matchCount++;
                    }
                }

                for (int i = 0; i < list.Count; i++)
                {
                    strRelease.Append(list.GetKey(i) + "<BR />");
                    strDownload.Append(list.GetByIndex(i) + "<BR />");
                    strDate.Append("" + "<BR />");
                }

                releaseOutput.Text = strRelease.ToString();
                downloadOutput.Text = strDownload.ToString();
            }
        }
        else
        {
            releaseOutput.Visible = false;
            errorLabel.Visible = true;
        }
    }
开发者ID:BackupTheBerlios,项目名称:mbunit-svn,代码行数:65,代码来源:downloads.aspx.cs

示例15: TestGetKeyBasic

        public void TestGetKeyBasic()
        {
            StringBuilder sblMsg = new StringBuilder(99);

            SortedList sl2 = null;

            StringBuilder sbl3 = new StringBuilder(99);
            StringBuilder sbl4 = new StringBuilder(99);
            StringBuilder sblWork1 = new StringBuilder(99);

            string s1 = null;
            string s2 = null;

            int i = 0;
            //
            // 	Constructor: Create SortedList using this as IComparer and default settings.
            //
            sl2 = new SortedList(this);

            //  Verify that the SortedList is not null.
            Assert.NotNull(sl2);

            //  Verify that the SortedList is empty.
            Assert.Equal(0, sl2.Count);

            //    Testcase: GetKey - key at index 0 , ArgExc expected
            Assert.Throws<ArgumentOutOfRangeException>(() =>
                {
                    sl2.GetKey(0);
                });

            //   Testcase: GetKey - null val, should pass
            sl2["first key"] = (string)null;
            Assert.Equal(1, sl2.Count);

            //   Testcase: vanila Set
            sl2.Clear();
            //   Testcase: add key-val pairs
            for (i = 0; i < 50; i++)
            {
                sblMsg.Length = 0;
                sblMsg.Append("key_");
                sblMsg.Append(i);
                s1 = sblMsg.ToString();

                sblMsg.Length = 0;
                sblMsg.Append("val_");
                sblMsg.Append(i);
                s2 = sblMsg.ToString();

                sl2.Add(s1, s2);
            }

            //
            //   now get their keys using GetKey
            //
            for (i = 0; i < 50; i++)
            {
                sblMsg.Length = 0;
                sblMsg.Append("key_");
                sblMsg.Append(i);
                s1 = sblMsg.ToString();
                Assert.True(((string)sl2.GetKey(sl2.IndexOfKey(s1))).Equals(s1));
            }

            Assert.Equal(50, sl2.Count);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:67,代码来源:GetKeyTests.cs


注:本文中的SortedList.GetKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。