【发布时间】:2011-09-16 11:53:52
【问题描述】:
各位, 我在下一个代码中出现编译错误('无法修改字典的返回值,因为它不是变量'):
public class BaseForm : Form
{
protected void StoreGridViewPosition(DataGridView grid)
{
if (grids.ContainsKey(grid))
{
grids[grid].RowIndex = grid.CurrentCell.RowIndex;
grids[grid].ColumnIndex = grid.CurrentCell.ColumnIndex;
}
Cell s = new Cell();
s.RowIndex = 213;
}
protected void LoadGridViewPosition(DataGridView grid)
{
}
private Dictionary<DataGridView, Cell> grids = new Dictionary<DataGridView, Cell>();
private struct Cell
{
public int RowIndex;
public int ColumnIndex;
}
}
但是,如果我将 struct(Cell) 替换为 class,那么它可以正常工作。 为什么会这样?
【问题讨论】: