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

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
Recent Announcements
Recent Announcements
IT之家
IT之家
人人都是产品经理
人人都是产品经理
G
Google Developers Blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
大猫的无限游戏
大猫的无限游戏
U
Unit 42
罗磊的独立博客
博客园 - Franky
WordPress大学
WordPress大学
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
SecWiki News
SecWiki News
V
Vulnerabilities – Threatpost
P
Privacy International News Feed
P
Palo Alto Networks Blog
F
Fortinet All Blogs
P
Proofpoint News Feed
博客园 - 叶小钗
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
Spread Privacy
Spread Privacy
S
Securelist
C
Cisco Blogs
I
Intezer
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Cyberwarzone
Cyberwarzone
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
宝玉的分享
宝玉的分享
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Engineering at Meta
Engineering at Meta
S
Schneier on Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
GbyAI
GbyAI
T
Troy Hunt's Blog
T
Threatpost
博客园 - 司徒正美
Y
Y Combinator Blog
Hugging Face - Blog
Hugging Face - Blog
AWS News Blog
AWS News Blog
T
The Blog of Author Tim Ferriss
G
GRAHAM CLULEY
N
Netflix TechBlog - Medium
酷 壳 – CoolShell
酷 壳 – CoolShell
Google DeepMind News
Google DeepMind News
Know Your Adversary
Know Your Adversary
S
SegmentFault 最新的问题

博客园 - 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---
        }

    }

}