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


C# ArrayList.Sort方法代码示例

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


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

示例1: GetBoxStatistics

 /// <summary>
 /// Inspects the members of the data Table, focusing on the named field.  It calculates
 /// the median of the values in the named field.
 /// </summary>
 /// <param name="self"></param>
 /// <param name="fieldName"></param>
 /// <returns></returns>
 public static BoxStatistics GetBoxStatistics(this DataTable self, string fieldName)
 {
     DataColumn dc = self.Columns[fieldName];
     ArrayList lst = new ArrayList();
     foreach (DataRow row in self.Rows)
     {
         lst.Add(row[fieldName]);
     }
     lst.Sort();
     BoxStatistics result = new BoxStatistics();
     if (lst.Count % 2 == 0)
     {
         if (dc.DataType == typeof(string))
         {
         }
         // For an even number of items, the mean is the average of the middle two values (after sorting)
         double high = Convert.ToDouble(lst.Count / 2);
         double low = Convert.ToDouble(lst.Count / 2 - 1);
         result.Median = (high + low) / 2;
     }
     else
     {
         result.Median = lst[(int)Math.Floor(lst.Count / (double)2)];
     }
     return result;
 }
开发者ID:DIVEROVIEDO,项目名称:DotSpatial,代码行数:33,代码来源:DataTableStatisticsExt.cs

示例2: Main

        static void Main(string[] args)
        {
            ArrayList list = new ArrayList();
            list.Add(new Person("Jim", 30));
            list.Add(new Person("Bob", 25));
            list.Add(new Person("Bert", 27));
            list.Add(new Person("Ernie", 22));
            Console.WriteLine("Unsorted people:");
            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine("{0} ({1})", (list[i] as Person).Name, (list[i] as Person).Age);
            }
            Console.WriteLine();
            Console.WriteLine(
            "People sorted with default comparer (by age):");
            list.Sort();
            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine("{0} ({1})",(list[i] as Person).Name, (list[i] as Person).Age);
            }
            Console.WriteLine();
            Console.WriteLine(
            "People sorted with nondefault comparer (by name):");
            list.Sort(PersonComparerName.Default);
            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine("{0} ({1})", (list[i] as Person).Name, (list[i] as Person).Age);
            }

            Console.ReadKey();
        }
开发者ID:ktjones,项目名称:BVCS2012,代码行数:31,代码来源:Program.cs

示例3: Main

 static void Main(string[] args)
 {
     ArrayList list = new ArrayList() ; 
     list.Add(new Person("Jim", 30)); 
     list.Add(new Person("Bob", 25)); 
     list.Add(new Person("Bert", 27)); 
     list.Add(new Person("Ernie", 22)); 
     Console.WriteLine ("Unsorted people: ") ; 
             // Несортированный список людей 
     for (int i = 0; i < list.Count; i++) 
     { 
         Console.WriteLine("{0} ({1})", (list[i] as Person).Name, (list[i] as Person).Age); 
     } 
     Console.WriteLine(); 
     Console.WriteLine("People sorted with default comparer (by age):"); 
             // Список людей, отсортированный (по возрасту) 
             //с помощью метода сравнения по умолчанию 
     list.Sort();
     for (int i = 0; i < list.Count; i++)
     {
         Console.WriteLine("{0} ({1})", (list[i] as Person).Name, (list[i] as Person).Age);
     }
     Console.WriteLine(); 
     Console.WriteLine("People sorted with nondefault comparer (by name):"); 
             // Список людей, отсортированный (по имени) с помощью 
             // метода сравнения не по умолчанию 
     list.Sort(PersonComparerName.Default); 
     for (int i = 0; i < list.Count; i++)
     {
         Console.WriteLine("{0} ({1})", (list[i] as Person).Name, (list[i] as Person).Age);
     } 
     Console.ReadKey(); 
 }
开发者ID:sev-it,项目名称:asp.net,代码行数:33,代码来源:Program.cs

示例4: Main

        static void Main(string[] args)
        {
            Console.WriteLine("Basic Array List Testing:");
            ArrayList al = new ArrayList();
            al.Add("Hello");
            al.Add("World");
            al.Add(5);
            al.Add(new FileStream("deleteme", FileMode.Create));

            Console.WriteLine("The array has " + al.Count + " items");

            foreach (object o in al)
            {
                Console.WriteLine(o.ToString());
            }

            Console.WriteLine("\nRemove, Insert and Sort Testing:");
            al = new ArrayList();
            al.Add("Hello");
            al.Add("World");
            al.Add("this");
            al.Add("is");
            al.Add("a");
            al.Add("test");

            Console.WriteLine("\nBefore:");
            foreach (object s in al)
                Console.WriteLine(s.ToString());


            al.Remove("test");
            al.Insert(4, "not");

            al.Sort();

            Console.WriteLine("\nAfter:");
            foreach (object s in al)
                Console.WriteLine(s.ToString());

            al.Sort(new reverseSorter());
            Console.WriteLine("\nReversed:");
            foreach (object s in al)
                Console.WriteLine(s.ToString());

            al.Reverse();
            Console.WriteLine("\nReversed again, different method:");
            foreach (object s in al)
                Console.WriteLine(s.ToString());

            Console.WriteLine("\nBinary Search Example:");
            al = new ArrayList();
            al.AddRange(new string[] { "Hello", "World", "this", "is", "a", "test" });
            foreach (object s in al)
                Console.Write(s + " ");
            Console.WriteLine("\n\"this\" is at index: " + al.BinarySearch("this"));
        }
开发者ID:oblivious,项目名称:Oblivious,代码行数:56,代码来源:Program.cs

示例5: getRequestURL

		/** 获取带参数的请求URL  @return String */
		public virtual string getRequestURL()
		{
			this.createSign();

			StringBuilder sb = new StringBuilder();
			ArrayList akeys=new ArrayList(parameters.Keys); 
			akeys.Sort();
			foreach(string k in akeys)
			{
				string v = (string)parameters[k];
                if (null != v && "key".CompareTo(k) != 0 && "spbill_create_ip".CompareTo(k)!=0) 
				{
					sb.Append(k + "=" + TenpayUtil.UrlEncode(v, getCharset()) + "&");
				} else if("spbill_create_ip".CompareTo(k) == 0){
					sb.Append(k + "=" + v.Replace(".", "%2E") + "&");
                    
				}
			}

			//去掉最后一个&
			if(sb.Length > 0)
			{
				sb.Remove(sb.Length-1, 1);
			}
							
			return this.getGateUrl() + "?" + sb.ToString();
		}
开发者ID:wujiang1984,项目名称:WechatBuilder,代码行数:28,代码来源:RequestHandler.cs

示例6: BuildNumber

            public override string BuildNumber(int Num, int Type)//  Type: 8 = 选8,7 = 选7,6 = 选6,5 = 选5, 4 = 选4,3 = 选3,2 = 选2,1 = 选1 
            {
                if ((Type != 8) && (Type != 7) && (Type != 6) && (Type != 5) && (Type != 4) && (Type != 3) && (Type != 2) && (Type != 1))
                    Type = 8;

                System.Random rd = new Random();
                StringBuilder sb = new StringBuilder();
                ArrayList al = new ArrayList();

                for (int i = 0; i < Num; i++)
                {
                    string LotteryNumber = "";
                    for (int j = 0; j < Type; j++)
                    {
                        int Ball = 0;
                        while ((Ball == 0) || isExistBall(al, Ball))
                            Ball = rd.Next(1, 80 + 1);
                        al.Add(Ball.ToString().PadLeft(2, '0'));
                    }
                    CompareToAscii compare = new CompareToAscii();
                    al.Sort(compare);

                    for (int j = 0; j < al.Count; j++)
                        LotteryNumber += al[j].ToString() + " ";

                    sb.Append(LotteryNumber.Trim() + "\n");
                }

                string Result = sb.ToString();
                Result = Result.Substring(0, Result.Length - 1);
                return Result;
            }
开发者ID:ichari,项目名称:ichari,代码行数:32,代码来源:SZKL8.cs

示例7: BuildNumber

 public override string BuildNumber(int Num)
 {
     Random random = new Random();
     StringBuilder builder = new StringBuilder();
     ArrayList al = new ArrayList();
     for (int i = 0; i < Num; i++)
     {
         al.Clear();
         for (int j = 0; j < 5; j++)
         {
             int ball = 0;
             while ((ball == 0) || base.isExistBall(al, ball))
             {
                 ball = random.Next(1, 0x10);
             }
             al.Add(ball.ToString().PadLeft(2, '0'));
         }
         LotteryBase.CompareToAscii comparer = new LotteryBase.CompareToAscii();
         al.Sort(comparer);
         string str = "";
         for (int k = 0; k < al.Count; k++)
         {
             str = str + al[k].ToString() + " ";
         }
         builder.Append(str.Trim() + "\n");
     }
     string str2 = builder.ToString();
     return str2.Substring(0, str2.Length - 1);
 }
开发者ID:NoobSkie,项目名称:taobao-shop-helper,代码行数:29,代码来源:TJFC15X5.cs

示例8: Main

        static void Main(string[] args)
        {
            ArrayList a = new ArrayList();
            a.Add("Arnold");
            a.Add("Smith");
            a.Add("Cordiner");
            a.Add("Mitchel");

            a.Sort();

            foreach (string name in a)
            {
                System.Console.WriteLine("{0}",name);
            }

            printContents(a);

            // *********** UN-COMMENT THE ABOVE CODE ************

            //1) what 'using' statement (namespace) do you need to
            //add to this code (at the top of the file)to get it to run?
            // Add it and then step into the program (F11)
            //2) add code here that uses the Sort method of the ArrayList
            // to sort into alphabetical order

            // add code here to display again all names in the
            //Array List in the console

            //3) Put the repeated code for displaying the contents
            // of the ArrayList in a seperate method
            // make sure that you pass the ArrayList to this method

            Console.ReadLine();
            System.Console.ReadLine();
        }
开发者ID:Andrew-Walker,项目名称:Software-Development-2,代码行数:35,代码来源:Class8.cs

示例9: winner

        public int winner(string[] votes)
        {
            int ret = -1;
            int soFar = int.MaxValue;
            ArrayList val = new ArrayList();
            for (int j = 0; j < votes[0].Length; j++)
            {
                int c = 0;
                for (int i = 0; i < votes.Length; i++)
                {
                    c += (votes[i][j] - 'a');
                }
                val.Add(c);

                if (soFar > c)
                {
                    soFar = c;
                    ret = j;
                }
            }

            val.Sort();
            if (val.Count > 1 && (int)val[1] == soFar)
                return -1;

            return ret;
        }
开发者ID:karunasagark,项目名称:ps,代码行数:27,代码来源:p1.cs

示例10: createSHA1Sign

        //����sha1ǩ��
        public string createSHA1Sign()
        {
            StringBuilder sb = new StringBuilder();
            ArrayList akeys = new ArrayList(parameters.Keys);
            akeys.Sort();

            foreach (string k in akeys)
            {
                string v = (string)parameters[k];
                if (null != v && "".CompareTo(v) != 0
                       && "sign".CompareTo(k) != 0 && "key".CompareTo(k) != 0)
                {
                    if (sb.Length == 0)
                    {
                        sb.Append(k + "=" + v);
                    }
                    else
                    {
                        sb.Append("&" + k + "=" + v);
                    }
                }
            }
            string paySign = SHA1Util.getSha1(sb.ToString()).ToString().ToLower();

            //debug��Ϣ
            this.setDebugInfo(sb.ToString() + " => sign:" + paySign);
            return paySign;
        }
开发者ID:yi724926089,项目名称:MyWx,代码行数:29,代码来源:RequestHandler.cs

示例11: GetControls

        /// <summary>
        /// 
        /// </summary>
        /// <param name="container"></param>
        /// <returns></returns>
        protected override object[] GetControls(IContainer container)
        {
            ComponentCollection components = container.Components;
            ArrayList controls = new ArrayList();

            foreach (IComponent component in components)
            {
                if (component is System.Web.UI.Control)
                {
                    Control c = (Control)component;

                    List<ButtonBase> buttons = ControlUtils.FindControls<ButtonBase>(c);

                    if (buttons != null && buttons.Count > 0)
                    {
                        foreach (ButtonBase btn in buttons)
                        {
                            if (btn.ID.IsNotEmpty() && !controls.Contains(btn.ID))
                            {
                                controls.Add(btn.ID);
                            }
                        }                        
                    }
                }
            }

            controls.Sort(Comparer.Default);

            return controls.ToArray();
        }
开发者ID:shalves,项目名称:Ext.NET.Community,代码行数:35,代码来源:ButtonConverter.cs

示例12: Alipay_Notify

        private string _transport = ""; //访问模式

        #endregion Fields

        #region Constructors

        /// <summary>
        /// 构造函数
        /// 从配置文件中初始化变量
        /// </summary>
        /// <param name="inputPara">通知返回来的参数数组</param>
        /// <param name="notify_id">验证通知ID</param>
        /// <param name="partner">合作身份者ID</param>
        /// <param name="key">安全校验码</param>
        /// <param name="input_charset">编码格式</param>
        /// <param name="sign_type">加密类型</param>
        /// <param name="transport">访问模式</param>
        public Alipay_Notify(ArrayList inputPara, string notify_id, string partner, string key, string input_charset, string sign_type, string transport)
        {
            _transport = transport;
            if (_transport == "https")
            {
                gateway = "https://www.alipay.com/cooperate/gateway.do?";
            }
            else
            {
                gateway = "http://notify.alipay.com/trade/notify_query.do?";
            }

            _partner = partner.Trim();
            _key = key.Trim();
            _input_charset = input_charset;
            _sign_type = sign_type.ToUpper();

            sPara = Alipay_Function.Para_filter(inputPara);  //过滤空值、sign与sign_type参数
            sPara.Sort();                                   //得到从字母a到z排序后的加密参数数组
            //获得签名结果
            mysign = Alipay_Function.Build_mysign(sPara, _key, _sign_type, _input_charset);

            //获取远程服务器ATN结果,验证是否是支付宝服务器发来的请求
            responseTxt = Verify(notify_id);
        }
开发者ID:svn2github,项目名称:Voodoo,代码行数:42,代码来源:alipay_notify.cs

示例13: Initialize

        public void Initialize(bool _includeDrafts)
        {
            // get the list of blogs, determine how many items we will be displaying,
            // and then have that drive the view mode
            string[] blogIds = BlogSettings.GetBlogIds();
            int itemCount = (_includeDrafts ? 1 : 0) + 1 + blogIds.Length;
            _showLargeIcons = itemCount <= 5;

            // configure owner draw
            DrawMode = DrawMode.OwnerDrawFixed;
            SelectionMode = SelectionMode.One;
            HorizontalScrollbar = false;
            IntegralHeight = false;
            ItemHeight = CalculateItemHeight(_showLargeIcons);

            // populate list
            if (_includeDrafts)
                _draftsIndex = Items.Add(new PostSourceItem(new LocalDraftsPostSource(), this));
            _recentPostsIndex = Items.Add(new PostSourceItem(new LocalRecentPostsPostSource(), this));

            ArrayList blogs = new ArrayList();
            foreach (string blogId in BlogSettings.GetBlogIds())
            {
                blogs.Add(new PostSourceItem(Res.Get(StringId.Blog), new RemoteWeblogBlogPostSource(blogId), this));
            }
            blogs.Sort();
            Items.AddRange(blogs.ToArray());
        }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:28,代码来源:BlogPostSourceListBox.cs

示例14: GetContextMenu

        public ContextMenu GetContextMenu()
        {
            ContextMenu cm = new ContextMenu();

            // add items in the same order that we encounter them, visually

            // iterate through children, looking for Action objects
            ArrayList al = new ArrayList();

            foreach (Control c in Controls)
                if ((c is Action) || (c is GroupBox))
                    al.Add(c);

            // now, sort these by y position
            al.Sort(this);

            // now, iterate through them, creating menu items for them
            foreach (Control c in al)
            {
                if (c is Action)
                {
                    Action ac = (Action)c;
                    MenuItem mi = new MenuItem(ac.Text, new EventHandler(cm_OnMenuClick));
                    mi.Enabled = ac.Enabled;
                    mi.Tag = ac;
                    cm.MenuItems.Add(mi);
                }
                else if (c is GroupBox)
                    cm.MenuItems.Add(new MenuItem("-"));
            }

            return cm;
        }
开发者ID:FarazShaikh,项目名称:likewise-open,代码行数:33,代码来源:ActionBox.cs

示例15: PrivateTestSort

		private void PrivateTestSort(ArrayList arrayList) 
		{	
			Random random = new Random(1027);

			// Sort arrays of lengths up to 200

			for (int i = 1; i < 200; i++) 
			{
				for (int j = 0; j < i; j++) 
				{
					arrayList.Add(random.Next(0, 1000));
				}

				arrayList.Sort();

				for (int j = 1; j < i; j++) 
				{
					if ((int)arrayList[j] < (int)arrayList[j - 1]) 
					{
						Assert.Fail("ArrayList.Sort()");

						return;
					}
				}

				arrayList.Clear();
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:28,代码来源:NewArrayListTest.cs


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