惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Last Watchdog
The Last Watchdog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Secure Thoughts
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
T
Tor Project blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Vercel News
Vercel News
Last Week in AI
Last Week in AI
月光博客
月光博客
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
博客园 - 叶小钗
NISL@THU
NISL@THU
C
Check Point Blog
K
Kaspersky official blog
N
News and Events Feed by Topic
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
Arctic Wolf
T
Threatpost
GbyAI
GbyAI
L
LINUX DO - 热门话题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
N
News and Events Feed by Topic
Scott Helme
Scott Helme
P
Privacy International News Feed
The Register - Security
The Register - Security
G
GRAHAM CLULEY
Recorded Future
Recorded Future
Apple Machine Learning Research
Apple Machine Learning Research
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog
Project Zero
Project Zero
Cyberwarzone
Cyberwarzone
Webroot Blog
Webroot Blog
Microsoft Security Blog
Microsoft Security Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
D
DataBreaches.Net
J
Java Code Geeks
AWS News Blog
AWS News Blog
Help Net Security
Help Net Security
Engineering at Meta
Engineering at Meta
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
Google DeepMind News
Google DeepMind News

博客园 - Caviare

前台优化法则(YSlow) ASP.NET MVC源代码 启用IIS的Gzip压缩功能 web.sitemap Dynamic Generation SQL字符正则匹配 委托应用 WorkBook操作实例 判断大陆IPAddress Bertrand Meyer提出的设计模式的原则 - Caviare - 博客园 Web.cofig详解[转] UpdatePanel Control [转老赵博客] .Net环境下的缓存技术介绍 (转) [转]webservice和remoting在分布式程序中的应用 sql2005备份在sql2000中恢复 Excel WorkBook操作例 温故知新-Excel操作类 SQL collation设置 一张类的访问权限图,帮您加深概念 [转]您可能不知道的Asp.Net2.0技巧
迭代器和排序基本使用
Caviare · 2007-11-02 · via 博客园 - Caviare

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace testApp
{
    
public partial class Form1 : Form
    
{
        
public Form1()
        
{
            InitializeComponent();
            

        }

        
private void button1_Click(object sender, EventArgs e)
        
{
            usingIteration();
            usingComparer();
            
        }


        
/// <summary>
        
/// 迭代器使用Demo
        
/// </summary>

        void usingIteration()
        
{
            System.Text.StringBuilder sbShow 
= new StringBuilder();
            System.Collections.IEnumerator ie 
= this.comboBox1.Items.GetEnumerator();

            
while (ie.MoveNext())
            
{
                sbShow.AppendLine(ie.Current.ToString());
            }

            MessageBox.Show(sbShow.ToString());
            
/*
            ---line1---
            ---line5---
            ---line3---
            ---line2---
            ---line4---
            ---line7---
            ---line8---
            ---line6---
             
*/

        }


        
/// <summary>
        
/// LIST排序Demo
        
/// </summary>

        void usingComparer()
        
{
            StringSort sort 
= new StringSort();
            System.Collections.ArrayList arrList 
= new System.Collections.ArrayList(comboBox1.Items);
            arrList.Sort(sort);
            System.Text.StringBuilder sbShow 
= new StringBuilder();
            
for (int i = 0; i < arrList.Count; i++)
            
{
                sbShow.AppendLine(arrList[i].ToString());
            }

            MessageBox.Show(sbShow.ToString());
            
/*
            ---line1---
            ---line2---
            ---line3---
            ---line4---
            ---line5---
            ---line6---
            ---line7---
            ---line8---
             
*/

        }

    }


    
public class StringSort : System.Collections.IComparer
    
{
        
public int Compare(object x, object y)
        
{
            
string str1 = x as string;
            
string str2 = y as string;
            
if (str1 == null || str2 == null)
            
{
                
throw new Exception("Item Error!");
            }

            
else
            
{
                
if (intGetIndex(str1) < intGetIndex(str2))
                
{
                    
return -1;
                }

                
else
                
{
                    
return 0;
                }

            }

        }

        
int intGetIndex(string str)
        
{
            
return Convert.ToInt32(str.Substring(71));//---line1---
        }

    }

}