Public Property Cell(ByVal row_index As Integer, ByVal col_index As Integer) As Object
Get
Return _excel.Cells(row_index, col_index).value
End Get
Set(ByVal value As Object)
_excel.Cells(row_index, col_index).value = value
End Set
End Property
谢谢。
------解决思路----------------------
无法直接翻译,c#不支持这类带参数的属性。你可以把它分别变为两个 Get_XXX 和 Set_XXX 普通方法来在C#中定义。
------解决思路----------------------
public object this[int x, int y]
{
get ...
set ...
}
------解决思路----------------------
在 vb.net 中的 Item 对应 c# 的 this。而这个 Cell 属性不是。
------解决思路----------------------
可以这样写
private static string[,] Cell = new string[10, 10];
public string this[int x, int y] //设置该类的索引器
{
get { return Cell[x, y]; }
set { Cell[x, y] = value; }
}
static void Main(string[] args)
{
Cell[2, 3] = "abcd";
Cell[4, 1] = "123";
Console.WriteLine("{0} {1}", Cell[4, 1], Cell[2, 3]);
}
不过写成两个方法要稳妥些