2013-12-19 27 views
0

這是我在web服務代碼傳遞值在一個陣列中的web服務

private object[] _myObjectVariableList = new object[7]; 

public object[] MyObjectVariableList 
{ 
    get { return _myObjectVariableList; } 
    set { _myObjectVariableList = value; } 
} 

,當我傳遞值它使用

AuditTrail auditclass = new AuditTrail(); 
auditclass.MyObjectVariableList[indexCounter] = myTextBox.Text; 

到我收到錯誤

你調用的對象是空的。

我真的不知道發生了什麼

任何想法?

回答

1

你需要初始化客戶端列表

AuditTrail auditclass = new AuditTrail(); 

auditclass.MyObjectVariableList = new object[7]; 

或服務類的構造函數初始化屬性值

public class AuditTrail 
{ 
    private object[] _myObjectVariableList; 

    public object[] MyObjectVariableList 
    { 
     get { return _myObjectVariableList; } 
     set { _myObjectVariableList = value; } 
    } 
    public AuditTrail() 
    { 
     MyObjectVariableList= new object[7]; 
    } 
}