Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;
Using System. collections;
Using System. reflection;
Using System. Text. regularexpressions;
Namespace Leleapplication1
{
Public Static Class Program
{
/// <Summary>
/// Entry Function
/// </Summary>
/// <Param name = "ARGs"> </param>
Static Void Main ( String [] ARGs)
{
List < String > Oldstrlist = New List < String > ()
{
" 12 " , " ZH " , " CN " ," 2e " , " 0a " , " 56 " , " FF " , " 00 "
};
Console. Write ("Old list:"+ Oldstrlist. Count +"->");
Foreach(StringStrInOldstrlist) console. Write (STR +" ");
Console. writeline ("");
List <String> Newhexlist = oldstrlist. hexfilter (
(P) =>
{
BoolBlstatus =False;
Try
{
Convert. toint32 (p, 16 ); Blstatus = True ;
}
Catch
{
Blstatus = False ;
}
return blstatus;
}< br>). tolist ();
Console. Write ("New List:"+ Newhexlist. Count +"->");
Foreach(StringStrInNewhexlist) console. Write (STR +" ");
Console. Readline ();
}
/// <Summary>
/// Filter out non-hexadecimal characters
/// </Summary>
/// <Typeparam name = "T"> </typeparam>
/// <Param name = "Source"> </param>
/// <Param name = "Predicate"> </param>
/// <Returns> </returns>
Static Ienumerable <t> hexfilter <t> ( This Ienumerable <t> source, func <t, Bool > Predicate)
{
Foreach (T item In Source)
{
If (Predicate (item )) Yield Return Item;
}
}
}
}