读书人

一个VB转C#的有关问题

发布时间: 2011-12-29 22:09:38 作者: rapoo

一个VB转C#的问题
Default Public ReadOnly Property Item(ByVal index As Integer) As Contact
Get
Return CType(List.Item(index), Contact)
End Get
End Property
用C#怎么写,谢谢

[解决办法]
当前类继承于System.Collections.CollectionBase
//Contact是一个类

完整如下:

using System;
using System.Collections.Generic;
using System.Text;

public class ContactS : System.Collections.CollectionBase
{

public void Add(Contact ContactObj)
{
List.Add(ContactObj);
}

public void Remove(int index)
{
List.RemoveAt(index);
}
public Contact this[int index]
{
get
{
return (Contact)List[index];
}
}

}

调用:

//添加到集合
ContactS cons=new ContactS();
Contact con=new Contact();
//设置con对象的值
cons.Add(con);

获取对象:
Contact con1=new Contact();
con1=cons[0];


读书人网 >C#

热点推荐