0

In my application, i want to have a list like this

Group  Kind   TableName   Condition
-----  ----   ---------   ----------
sh      Send    TableA      Null
sh      New     TableB      kbsn=0
jn      Receive TableC       Null

This list must use in whole of my application and it's values always is constant. Now,how do i define this list in a class in my C# application and how can i read or query from this list?

ozzy_mra
  • 577
  • 4
  • 11
  • 24
  • 1
    Is [way of representing immutable list](http://stackoverflow.com/questions/3612054/what-is-the-best-way-of-representing-an-immutable-list-in-net) what you are looking for? – Alexei Levenkov Nov 11 '14 at 07:09

2 Answers2

1

Create a Class and add fields to it.

Here is a code:

Class MyCustomClass
{
    public string Group { get; set; }   
    public string Kind { get; set; }  
    public string TableName { get; set; }  
    public string Condition { get; set; }  
}

Define static list of MyCustomClass and initialize in application at proper place and use it everywhere in application.

static List<MyCustomClass> lstMyCustomClass  = new List<MyCustomClass> { .... };
sandip patil
  • 191
  • 4
  • 1
    Add **readonly** after static and expose it as `IEnumerable` or `IReadOnlyCollection` (in .Net 4.5) in order to prevent modifications by its clients. – galenus Nov 11 '14 at 07:29
  • can you use ImmutableList or ReadOnlyCollection ? – Kiquenet Dec 21 '22 at 10:05
1

Please follow the following code, which I hope will solve your problem.

First of all, you have one class for all enums, so that you can declare all list components:

public enum GroupEnum
{
    sh,
    sh,
    jn
}

public enum TableNameEnum
{
    TableA,
    TableB,
    TableC
}

public class MyCustomClass
{
    public GroupEnum Group { get; set; }
    public KindEnum Kind { get; set; }
    public TableNameEnum TableName { get; set; }
}

When you make list type object of MyCustomClass, you have all static values of group, kind, and table name etc. so that you can filter that list according to that static values through LINQ in C#.

Peter Duniho
  • 68,759
  • 7
  • 102
  • 136