【C#】自定义数组默认初始化

自定义数组初始化
public class ObRoleMessage : MessageBase
{
    public bool isKh;
    public int id;
}

    private ObRoleMessage[] CollectRoleMsg()
    {
        var roleMsg = ObGetMessage.Instance._dicObRole;
        if (roleMsg.Count != 0)
        {
            List _roleID = new List(roleMsg.Keys);
            ObRoleMessage[] obRoleMsg = new ObRoleMessage[roleMsg.Keys.Count];
            for (int i = 0; i < roleMsg.Keys.Count; i++)
            {
                obRoleMsg[i] = new ObRoleMessage();
                obRoleMsg[i].isKh = roleMsg[_roleID[i]].isKh;
                obRoleMsg[i].id = roleMsg[_roleID[i]].id;

            }
            return obRoleMsg;
        }
        return null;
    }


你可能感兴趣的:(C#)