C#定义一个对象数组

时间:2014-08-19 14:51:22

标签: c# arrays object

我尽我所能并用Google搜索,但我似乎被卡住了

我有一个看起来像这样的对象:

SubmitJob(HTSignCreator.XMPieProduction.XMPUser XMPUser, string inJobTicket, string inPriority, string inTouchPointID, HTSignCreator.XMPieProduction.Property[] inProps)

我定义了

var user = new XMPieProduction.XMPUser
                    {
                        Username = "user",
                        Password = "pass"
                    };

我唯一的问题是这个HTSignCreator.XMPieProduction.Property [] inProps参数....

HTSignCreator.XMPieProduction.Property只有两个字符串属性(m_name和m_value),,,

我正在使用一个给我这种结构的网络服务..

我尝试了所有内容来创建inProps参数,但似乎没有任何效果,

我试过了:

HTSignCreator.XMPieProduction.Property props = new HTSignCreator.XMPieProduction.Property
                    {
                        m_Name = "0",
                        m_Value = "0"
                    };

但是当我调用jobId = productionWrapper.Client.SubmitJob(user,ticketId," 0"," 0",props)时; 我们会说道具论证无效......

我不知道如何定义Property []参数......

任何想法???

1 个答案:

答案 0 :(得分:1)

您需要初始化数组以及其中的项

HTSignCreator.XMPieProduction.Property[] props = 
    new HTSignCreator.XMPieProduction.Property []
        {
            new HTSignCreator.XMPieProduction.Property
                {
                    m_Name = "0",
                    m_Value = "0"
                }
        };

或者如果您已经在阵列外部初始化了实例:

HTSignCreator.XMPieProduction.Property prop =        
     new HTSignCreator.XMPieProduction.Property
            {
                m_Name = "0",
                m_Value = "0"
            };

HTSignCreator.XMPieProduction.Property[] props = 
    new HTSignCreator.XMPieProduction.Property []
        {
            prop 
        };

我还建议使用varusing来减少类型名称的长度:

using HTSignCreator.XMPieProduction;


...

var props = 
    new Property[]
        {
            new Property
                {
                    m_Name = "0",
                    m_Value = "0"
                }
        };