Feasible way to get values from dictionary

My game has a function that returns a string. I want to evaluate that the string returned is present in English dictionary. I have my own customised dictionary with all the valid words, but I don’t know how to use it. One of the way which I could think of is to make an array of string elements & add all the valid words into it. But the total no. of words are 172722 & making an array such big would result in a lag.

What can be the alternate solution for this?

use a Hashset

A HashSet holds a set of objects in a way that allows you to easily and quickly determine whether an object is in the set or not. Put all the english words into a hashset (perhaps make them all lowercase, and only perform lowercase tests).

Then, you use HashSet.Contains to check if the word is in there. It’s extremely fast.

Using Lists, arrays, etc, is going to be much much slower. HashSet can probably handle 172,000 values fairly well. It would be easy to test it and try it out.

HashSet is the way to go if you are only trying to determine if an item exists within a collection.