Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I find this source code that allows me Binding ComboBox directly to enum values but I do not understand this instruction

C#
public IList<UserType> UserTypes
{
    get
    {
        // Will result in a list like {"Tester", "Engineer"}
        return Enum.GetValues(typeof(UserType)).Cast<UserType>().ToList<UserType>();
    }
}
 
public UserType UserType
{
	get;
	set;
}


knowing that this code I find it in this site

What I have tried:

i try to test this code and it's works but don't understand that.
Posted
Updated 19-Jan-18 9:40am
Comments
[no name] 19-Jan-18 8:54am    
This is not a question.As this is a lack of understanding you have to start learning .NET properly.

Have a look at this CodeProject article Binding and Using Friendly Enums in WPF[^]

But if you have a query about the code you found then you should direct your questions to the authors[^] of that code
 
Share this answer
 
Enum 
    .GetValues(typeof(UserType)) // Get all values of the enum... This will return an array of object
    .Cast<UserType>()            // cast each object to enum UserType - This will return a IEnumerable<UserType>
    .ToList<UserType>();         // Convert the IEnumerable<UserType> to a list of UserTypes


This is pretty basic... It is like asking how to loop
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900