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

推荐订阅源

P
Palo Alto Networks Blog
N
Netflix TechBlog - Medium
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
B
Blog
MyScale Blog
MyScale Blog
Microsoft Security Blog
Microsoft Security Blog
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Hugging Face - Blog
Hugging Face - Blog
S
Schneier on Security
Project Zero
Project Zero
T
Tenable Blog
T
Tor Project blog
U
Unit 42
G
GRAHAM CLULEY
N
News and Events Feed by Topic
P
Proofpoint News Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Y
Y Combinator Blog
C
Cybersecurity and Infrastructure Security Agency CISA
腾讯CDC
博客园 - 叶小钗
M
MIT News - Artificial intelligence
Vercel News
Vercel News
T
Threat Research - Cisco Blogs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
The Exploit Database - CXSecurity.com
P
Privacy & Cybersecurity Law Blog
I
Intezer
博客园 - 聂微东
SecWiki News
SecWiki News
Scott Helme
Scott Helme
C
Cyber Attacks, Cyber Crime and Cyber Security
IT之家
IT之家
量子位
S
Secure Thoughts
The Cloudflare Blog
博客园 - 司徒正美
Know Your Adversary
Know Your Adversary
Hacker News: Ask HN
Hacker News: Ask HN
V
Vulnerabilities – Threatpost
Simon Willison's Weblog
Simon Willison's Weblog
N
News | PayPal Newsroom
C
Check Point Blog
Spread Privacy
Spread Privacy
C
CXSECURITY Database RSS Feed - CXSecurity.com
Cyberwarzone
Cyberwarzone

博客园 - Tobin

41岁的大龄程序员,苟着苟着,要为以后做打算了 UC_Center整合单点登录后远程注册不激活问题的解决办法 AspExe - a small ASP.NET compiler and executor for document generation 在as3中Embed(绑定)flash动画元素 - Tobin - 博客园 Embedding Resources with AS3 Configure the max limit for concurrent TCP connections [转]翻译:使用.net3.5的缓存池和SocketAsyncEventArgs类创建socket服务器 强制将IE,Chrome设置为指定兼容模式来解析(转) - Tobin - 博客园 工商银行,千万别用,转账不成功一样收手续费 MySQL vs NoSQL 效率与成本之争(转) 使用ASP.NET Global.asax 文件(转) [MySql识记]create utf8 database - Tobin npgsql连接postgresql数据库 由浅到深了解JavaScript类[转过来的收藏] javascript改变this指针 哪个美女最漂亮,自己写的js图片自适应切换 javascript操作cookie实例 [图解] 你不知道的 JavaScript - “this”(转) 关于游戏开发中的A*/A-star的寻路算法的问题
对与list<>泛型的一些操作方法
Tobin · 2008-07-01 · via 博客园 - Tobin

如果自己定义了一个结构

 1 public struct iPoint
 2     {
 3         private SinglePoint _c;
 4         /// <summary>
 5         /// 当前点的坐标
 6         /// </summary>
 7         public SinglePoint C
 8         {
 9             get { return _c; }
10             set { _c = value; }
11         }
12         public iPoint(SinglePoint _c)
13         {
14                        this._c = _c;
15         }
16     }
17     public struct SinglePoint
18     {
19         private int _y;
20         private int _x;
21         public int Y
22         {
23             get { return _y; }
24             set { _y = value; }
25         }
26         public int X
27         {
28             get { return _x; }
29             set { _x = value; }
30         }
31         public SinglePoint(int _y, int _x)
32         {
33             this._y = _y;
34             this._x = _x;
35         }
36     }

但如果要iPoint[] list=new iPoint[1];这里势必要声明数组的初始大小,这样在实际操作中就比较麻烦,它不要javascript里的数组那样灵活。这个时候就需要用到泛型list<>来做一些处理,但是泛型也有很多不便,为了能记住我将泛型一些简单的操作记录下来
这些操作包括:
1.list<>.find();
2.list<>.sort();
先说find(),先声明一个list

1  List<iPoint> List = new List<iPoint>();

这里当find的时候会发现 public T Find(Predicate<T> match); 这个Predicate<T> match我们改怎么处理呢?
下面我给出一个示例:我们首先要先建立一个finder,我们仅比较struct ipoint里的C的坐标是否相等 其他我们不做比较!

 1 public class Finder
 2     {
 3         private iPoint _c;
 4         /// <summary>
 5         /// 当前点的坐标
 6         /// </summary>
 7         public iPoint C
 8         {
 9             get { return _c; }
10             set { _c = value; }
11         }
12         public Finder(iPoint cPoint)
13         {
14             this._c = cPoint;
15         }
16         public bool FindCurrentPoint(iPoint CurrPoint)
17         {
18             if (C.C.X == CurrPoint.C.X && C.C.Y == CurrPoint.C.Y)
19             {
20                 return true;
21             }
22             else
23             {
24                 return false;
25             }
26         }
27     }

这里开始查找:

1 iPoint tempPoint = new iPoint(1,2);
2             Finder ifinder=new Finder(tempPoint);
3             iPoint findRes= ClosedList.Find( new Predicate<iPoint>(ifinder.FindCurrentPoint));

OK,这里就找到了Y=1,X=2的iPoint对象了。
    再来说sort()
    我们要先建立一个继承自IComparer<>的类

 public class FComparer : IComparer<iPoint>
        
{
            
//实现C.X升序
            public int Compare(iPoint x, iPoint y)
            
{
                
return (x.C.X.CompareTo(y.C.X));
            }

        }

调用就更简单了
只需要

1 list.Sort(new FComparer());

就可以了,至于为什么要这样写,我也说不出个所以然来,先记下来用的多了就会了!