It is really convenient to use generics, as shown below:ProgramThe specified type will be searched in the arraylist
Using System; Using System. Collections. Generic; Using System. LINQ; Using System. text; Using System. collections; Namespace LINQ query operation { Class Program { Static void Main ( String [] ARGs) {search for the specified type < Bool > (); Search for the specified type < Int > (); Search for the specified type < String > (); Console . Readline ();} Private Static void Search for the specified type <t> (){ Arraylist Randomlist = New Arraylist (); Randomlist. add (1); randomlist. add (2); randomlist. add (3); randomlist. add (4); randomlist. add (5); randomlist. add ( "One" ); Randomlist. Add ( "Two" ); Randomlist. Add ( "Three" ); Randomlist. Add ( "Four" ); Randomlist. Add ( "Five" ); Randomlist. Add ( True ); Randomlist. Add ( False ); Randomlist. Add ( True ); VaR Query = randomlist. oftype <t> (); Foreach ( VaR Item In Query ){Console . Writeline (item );}}}}
The result is as follows: