创建一个类但是函数的参数是作为ref Class数组传递的

时间:2016-08-09 12:00:36

标签: c#-4.0

这是代码 我有这样的课程,

public partial class Property
{

private string keyField;

private object valueField;

/// <remarks/>    [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
public string key
{
get
{
return this.keyField;
}
set
{
this.keyField = value;
}
}

/// <remarks/>            [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
public object value
{
get
{
return this.valueField;
}
set
{
this.valueField = value;
}
}
}

并且使用两个参数

声明一个函数
public VerifyRetailO VerifyRetail(ref Property[] Properties, VerifyRetailI VerifyRetailRq)

但是我很难分配第一个参数值,不知道我应该如何通过i。 请帮忙

2 个答案:

答案 0 :(得分:0)

只需在方法调用中包含ref关键字:

Property[] Properties = new....//Instantiate first param or get it from somwhere
VerifyRetailI VerifyRetailRq = new..//Instantiate second param or get it from somwhere
VerifyRetail(ref Properties, VerifyRetailRq);

答案 1 :(得分:0)

声明

Property[]classarr=newProperty[10];
for(inti=0;i<classarr.Length;i++)
{
//initialization
classarr[i]=newProperty();
}

Property[] oprop = new Property[1];
oprop[0] = new Property();
oprop[0].key = "D_Key";
oprop[0].value = "D_Value";