A problem with this solution and what you have asked for is that the JSON file you are reading may contain millions of objects and this technique has certain inefficiencies which will not scale well.
You should not keep building a HashSet from the static list of SQL keywords only to use it once and then throw it away (perhaps millions of times per file) -- which is what Linq will do in the background.
Furthermore, if all you want to know is whether or not any one value is in the set, then a full Intersection of the two sets isn't necessary (a Contains should be enough).
Here's another way to test a set of string values against a fixed set of strings which should be more efficient than intersecting sets:
namespace CP
{
public static partial class DicValCompare
{
private enum SQLstring
{
SELECT = 7
,
UPDATE = 2
,
CREATE = 6
,
UNION = 4
,
JOIN = 5
}
public static int
Main
(
)
{
int result = 0 ;
System.Collections.Generic.Dictionary<string,string> dictionary2 =
new System.Collections.Generic.Dictionary<string,string>
(
)
{
{ "Id" , null }
,
{ "FName" , "create" }
,
{ "LName" , "Denny" }
,
{ "DateofJoining" , null }
,
{ "Date" , "2023 - 08 - 01T00: 00:00" }
,
{ "CreatedBy" , "ICC0000389" }
} ;
bool isMatch = false ;
SQLstring sql ;
foreach ( string val in dictionary2.Values )
{
if
(
( val != null )
&&
( isMatch |= System.Enum.TryParse ( val , true , out sql ) )
)
{
break ;
}
}
return ( result ) ;
}
}
}