© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
18 replies
Jason_Bjorn

✅ [AllowedValue] not doing anything

Why is my code allowing the name "Jimmy" ?
using System.ComponentModel.DataAnnotations;

public class Foo
{
    [AllowedValues(new object [] {"Bill", "Bob"}, "Entered illegal name")]
    public string Name { get; set; }
}

class Program
{
    public static void Main()
    {
        Foo f = new()
        {
            Name = "Jimmy" // works ???
        };
    }
}
using System.ComponentModel.DataAnnotations;

public class Foo
{
    [AllowedValues(new object [] {"Bill", "Bob"}, "Entered illegal name")]
    public string Name { get; set; }
}

class Program
{
    public static void Main()
    {
        Foo f = new()
        {
            Name = "Jimmy" // works ???
        };
    }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ App diagnostics not doing anything (UWP)
C#CC# / help
3y ago
❔ Trouble doing anything with an SQLite database in ASP.NET
C#CC# / help
3y ago
❔ Method WriteToTable(); isn't doing anything to the database file
C#CC# / help
4y ago
HttpClient does not return anything
C#CC# / help
3y ago