【问题标题】:how can I use an array with a class using a dot operator如何使用点运算符将数组与类一起使用
【发布时间】:2016-08-30 21:21:06
【问题描述】:

使用系统;

我正在使用 string[] TalentSlots = new string[2]; 我想做一个 agent.talentSlots = blah blah 事情我该怎么做?

namespace warhammerRPGCB
{
    public class classes
    {
        string className;
        int stanceRed;
        int standGreen;
        string carrerSkills;
        string primaryChar;
        string[] talentSlots = new string[2];
        int focusSlot;
        int reputationSlot;
        int tacticSlot;

        public classes()
        {
            classes agent = new classes();
            agent.className = "Agent";
            agent.carrerSkills = "Charm, Education, Folklore, Guile, Intution";
            agent.stanceRed = 2;
            agent.standGreen = 2;
            agent.primaryChar = "Intelligence, Felloship";
            agent.tacticSlot = focusTalent, reputationTalent;
        }
    }
}

【问题讨论】:

    标签: c# arrays class


    【解决方案1】:

    你可以使用数组初始化器

    agent.talentSlots = new string[] {focusTalent,reputationTalent};
    

    【讨论】:

    • 注意可以推断出数组类型:agent.talentSlots = new [] { focusTalent, reputationTalent }
    猜你喜欢
    • 2015-11-09
    • 2020-04-15
    • 2013-04-21
    • 2020-02-13
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 2017-10-12
    • 1970-01-01
    相关资源
    最近更新 更多