'How to use Array.Contains in razorpages?

I'm currently having a problem using Contains inside cshtml file. I want to check if devgroup contains a user.

@{ 
                                    string[] devgroup = { "55", "53", "75" };
                                    var devdisplay = "none";
                                    var user = ViewBag.IDEmployee;
                                    if (devgroup.Contains(user))
                                    {
                                        devdisplay = "block";
                                    }

                                }

and I'm currently having an compile error.


Error   CS1929  'string[]' does not contain a definition for 'Contains' and the best extension method overload 'MemoryExtensions.Contains<T>(ReadOnlySpan<T>, T)' requires a receiver of type 'ReadOnlySpan<T>'



Solution 1:[1]

Try to use:

if (devgroup.ToList().Any(d=>d==user))

or

if (devgroup.ToList().Contains(user))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yiyi You