Search code examples
.netdatareader

How to implement data container with instance["variable_name"] access?


I am using DataTable["content_name"], DataReader["content_name"], but I do not know, how to create my own object using this way to access data.

I want to create datareader result container (DataTable makes me some unwanted queries to db on firebird).


Solution

  • Something like

    public class MyClass
    {
      private List<String> _myData;
    
      public MyClass()
      {
        _myData = new List<String>();
      }
    
      public String this[String argIndex]
      {
        get
        {
          return _myData[argIndex];
        }
        set
        {
          _myData[argIndex] = value;
        }
      }
    }
    

    It's the this bit that usually stumps you until you know it, bit unobvious...