Reputation: 83
I have created a static class which contains some static values list. Now I want to access these values out side from this class. I need to know how can I do this? The code example is provided below:
public class RoleList
{
static public List<RoleDetials> Roles()
{
List<RoleDetials> roleDetaildsList = new List<RoleDetials>();
roleDetaildsList.Add(new RoleDetials
{
Id = 1,
Name = "admin"
});
roleDetaildsList.Add(new RoleDetials
{
Id = 2,
Name = "sadmin"
});
roleDetaildsList.Add(new RoleDetials
{
Id = 3,
Name = "badmin"
});
return roleDetaildsList;
}
}
public class RoleDetials
{
public int Id { get; set; }
public string Name { get; set; }
}
I already tried to like below but this way not works as per C# syntax.
var allRoles = RoleList.ToList();
Upvotes: 0
Views: 91
Reputation: 31
To access to data is
List<RoleDetials> allRoles = RoleList.Roles();
And replace
static public List<RoleDetials> Roles()
For
public static List<RoleDetials> Roles()
Upvotes: 2
Reputation: 222542
You need to call the method as,
List<RoleDetials> roles = RoleList.Roles();
Upvotes: 0