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

推荐订阅源

N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
Hugging Face - Blog
Hugging Face - Blog
L
LINUX DO - 热门话题
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
D
Docker
C
Cyber Attacks, Cyber Crime and Cyber Security
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
T
Tenable Blog
P
Privacy International News Feed
Google DeepMind News
Google DeepMind News
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
Arctic Wolf
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cisco Blogs
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
The Hacker News
The Hacker News
Project Zero
Project Zero
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threatpost
V
Visual Studio Blog
The GitHub Blog
The GitHub Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
MongoDB | Blog
MongoDB | Blog
U
Unit 42
Scott Helme
Scott Helme
A
About on SuperTechFans
WordPress大学
WordPress大学
F
Fortinet All Blogs
大猫的无限游戏
大猫的无限游戏
G
GRAHAM CLULEY
Latest news
Latest news
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Schneier on Security

博客园 - greater

Matlab 7.0不断重启问题解决方法 安装Matlab过程中遇到拒绝访问怎么办? NUnit图解(一) [翻译]Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition 第二十四章 LINQ API编程(三) [翻译]Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition 第二十四章 LINQ API编程(二) [翻译]Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition 第二十四章 LINQ API编程(一) 迷人舞步 难译的英文单词 Linq 之Expression Tree再思考 VS2008代码段快捷方式小记 Linq To SQL分页失败后引发的思考 Linq之查询非泛型集合 函数式编程的浅议 Linq操作符之筛选特定位置的元素 Linq与斐波那契数列共舞 Linq的那些事——从Linq扩展方法回顾C#语言基础 Linq之C#3.0语言扩展 Linq to DataSet 之Access查询 从101 LINQ Samples开始
Linq To Object实例之过滤字符集
greater · 2008-06-09 · via 博客园 - greater

目前利用Linq To Object可以查询实现了IEnumerable<T>接口的未定义类型对象数组、自定义对象数组、泛型List和Dictionary、以及string等。当然进行编程之前要添加System.Core.dll引用和命名空间System.Linq,事实上VS2008已经在建立项目的时候自动添加了。

这次要做的是一个简单的winform程序主要用Linq to object来过滤字符集,然后绑定到相应的datagrid去。

先来看看完成后的效果图(通过鼠标点击改变测试字符集):
FontFilter.jpg

本实例省略调试代码!主要Linq实现步骤简述如下:

定义系统字符集
private List<FontFamily> systemFont = new List<FontFamily>();

 1    /// <summary>
 2        /// 获取已安装的字符集
 3        /// </summary>
 4        /// <returns>字符集list</returns>

 5        private List<FontFamily> GetAllFont()
 6      {
 7
 8            foreach (FontFamily f in FontFamily.Families)
 9           {
10                systemFont.Add(new FontFamily(f.Name));
11
12            }

13            return systemFont;
14        }

1 通过查询把结果集绑定到datagrid中去
      var query
2                  = from font in systemFont
3                     where font.Name.ToLower().StartsWith(txtFontFilter.Text.ToLower())&&font.IsStyleAvailable(FontStyle.Regular)
4                     select font;
5                   //Gray Zhang给了很好的建议font.IsStyleAvailable(FontStyle.Regular),在此感谢!
6            dgvFont.DataSource = query.ToList();//这里的ToList是必须的,为了在winform中生成List进行显示. ASP.net有所不同.

可能遇到的问题: 字体"......"不支持样式"Regular",也许是由于系统字体库出了问题,更新一下.如果有更好的解决该Exception方法,请各位贴出来,谢谢!

附件