小编Bal*_*arq的帖子

为什么C#的System.Collections库中没有ReadOnlyList <T>类?

阅读在C#中创建只读原始向量的问题(基本上,你不能这样做),

public readonly int[] Vector = new int[]{ 1, 2, 3, 4, 5 }; // You can still changes values
Run Code Online (Sandbox Code Playgroud)

我了解了ReadOnlyListBase.这是对象容器的基类,可以访问但不修改其位置.甚至在Microsoft msdn中也有一个例子.

http://msdn.microsoft.com/en-us/library/system.collections.readonlycollectionbase.aspx

我稍微修改了msdn中的示例以使用任何类型:

public class ReadOnlyList<T> : ReadOnlyCollectionBase {
    public ReadOnlyList(IList sourceList)  {
      InnerList.AddRange( sourceList );
    }

    public T this[int index]  {
      get  {
         return( (T) InnerList[ index ] );
      }
    }

    public int IndexOf(T value)  {
      return( InnerList.IndexOf( value ) );
    }



    public bool Contains(T value)  {
      return( InnerList.Contains( value ) ); …
Run Code Online (Sandbox Code Playgroud)

c# readonly generic-collections

23
推荐指数
1
解决办法
8018
查看次数

如何在Gtk#TreeView中管理特殊用途的按键?

我在Gtk#/ mono C#中有一个KeyPressed信号用于两个不同的目的,默认的TreeView中不存在:a)按TAB转到下一个单元格,b)按任意键开始编辑.

树视图是简单,它有一个ListStore仅示出的行和列,即,其保持表格数据.

我的代码如下.

[GLib.ConnectBefore]
protected void OnTableKeyPressed(object o, Gtk.KeyPressEventArgs args)
{
    int rowIndex;
    int colIndex;

    // Do not "eat" the key, by default
    args.RetVal = false;

    // Get the current position, needed in both cases.
    this.GetCurrentCell( out rowIndex, out colIndex );

    // Adapt the column
    colIndex += NumFixedColumns;

    if ( args.Event.Key != Gdk.Key.ISO_Enter ) {
        if ( args.Event.Key == Gdk.Key.Tab
          || args.Event.Key == Gdk.Key.ISO_Left_Tab )
        {
            if( args.Event.State …
Run Code Online (Sandbox Code Playgroud)

c# treeview gtk# cell

12
推荐指数
1
解决办法
524
查看次数

标签 统计

c# ×2

cell ×1

generic-collections ×1

gtk# ×1

readonly ×1

treeview ×1