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