Filter character set of a Linq To Object instance

Source: Internet
Author: User

Currently, you can use Linq To Object To query the undefined Object array, custom Object array, generic List, Dictionary, and string of the IEnumerable <T> interface. Of course, you need to add the System. Core. dll reference and namespace System. Linq before programming. In fact, VS2008 is automatically added when the project is under construction.

In this case, a simple winform program mainly uses Linq to object to filter character sets and then binds them to the corresponding datagrid.

First, let's take a look (click to change the test Character Set ):

Debugging code is omitted for this instance! The main steps for implementing Linq are described as follows:

Define system Character Set
Private List <FontFamily> systemFont = new List <FontFamily> ();

1 /// <summary>
2 // obtain the installed Character Set
3 /// </summary>
4 /// <returns> character set 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. Bind The result set to the datagrid through the query
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 gave a good suggestion to font. IsStyleAvailable (FontStyle. Regular). Thank you!
6 dgvFont. DataSource = query. ToList (); // ToList is required. In order to generate a List in winform for display, ASP.net is different.

Possible problems: font "...... "style" Regular "is not supported. It may be because of a problem with the system library. Please update it. if you have a better solution to this Exception, please post it. Thank you!

Attachment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.