C#, Can I move dictionary initial code out from the constructor?
Posted
by 5YrsLaterDBA
on Stack Overflow
See other posts from Stack Overflow
or by 5YrsLaterDBA
Published on 2010-05-11T15:59:58Z
Indexed on
2010/05/11
16:04 UTC
Read the original article
Hit count: 186
c#
Here is my code right now. But I would like to move those "Add" out from the constructor. Can we initialize Dictionary
when we new
it? or you have another better idea. Basically I want to define few characters which are used in many places.
public class User
{
public enum actionEnum
{
In,
Out,
Fail
}
public static Dictionary<actionEnum, String> loginAction = new Dictionary<actionEnum, string>();
public User()
{
loginAction.Add(actionEnum.In, "I");
loginAction.Add(actionEnum.Out, "O");
loginAction.Add(actionEnum.Fail, "F");
}
.....
}
© Stack Overflow or respective owner