Click here to Skip to main content
15,908,444 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear sir:

I have face a question that I made a program for data system, due to some resion, I don't want to use ADO.NET and Access MDB, I have made a struct as following:
C#
struct tablename
   {
     public string g1;
     public string g2;
     public double g3;
     public double g4;
     //there are total 17 fields;
     public tablename(string m_g1,string m_g2,double m_g3, double m_g4,//another total 17 fields)
       {
         g1=m_g1;
         g2=m_g2;
         g3=m_g3;
         g4=m_g4;
        //another totoal 17 fields

        }
     public static tablename[] table{
             new tablename("ISO9600","YES",56,512//another totoal 17 fields);
              new tablename("ISO9610","67S",321,25//another totoal 17 fields);
             new tablename("ISO9650","SDS",56,345//another totoal 17 fields);
             new tablename("ASME","KLGFGFDD",3556,5//another totoal 17 fields);

  }

I made the talbe in struct, and one table to one struct, there are maybe 200 or more tables, each table has 300 records or more. these tables are all in a DataLib class.
The problem is that how can i find the specified table and then find the specified data in tablename[]?

For exmaple:
String xxx; string yyy;
I want to find the table which named equal xxx, and find table.g2=yyy in xxx[], and enumator each fileds which unknown? how can I do this?

Thanks.
david jang
Posted
Updated 7-May-11 18:39pm
v4

1 solution

Check out LINQ to Objects[^], and many good samples can be found her[^]

I am sure it can help you solve your problem.

With LINQ you can build SQL like statements

var result = from t in table
             where t.g1 == "ISO9610"
             select t;

foreach (var r in result)
{
  Console.WriteLine("Result g1 = " + r.g1);
}
 
Share this answer
 
v2
Comments
fpso 9-May-11 20:36pm    
hi kim: I think you missunderstand my point, the point is that there are many different types of struct which contain data in one DataLib class, the key point is that use the class name and struct name to access the data. for example: string xxx is known, but I don't know if there is a struct also named "xxx" in class DataLib, so I have to check it in DataLib class. if it exist, then access the data through the name of "xxx[] table" . the question Briefly is to use string name to access struct and property in one class. May be reflection can do it, but performance problem.
Regards.
David jang
Kim Togo 10-May-11 3:47am    
I think I have misunderstood what you want.
DataLib class has an array of objects ? And this objects can be type of struct tablename ?
fpso 11-May-11 9:46am    
yes, in Datalibe class,there are maybe hundred of structs, each struct contain different data, i.e. each struct has different fields and number of fields. my headach is that i can not access the data in struct use the string compare with each struct's name, as you know, it is impossible to write hundred of "switch(tablename) {case tablename.tostring():}", there are hundred case situation. I just think that use string compare the name of struct in Datalib Class, if same, the progrm know that the request data is in this struct and then to access it. that's my requirement. similar in ADO.NET to access the table in MDB files.
Kim Togo 13-May-11 5:05am    
I think you have to build up a super struct, that holds all common information for all other struct. But "struct" do not support inherit only "class" has this.
Just like TextBox inherit from TextBoxBase that inherit from Control etc... and ending at object.
fpso 13-May-11 9:39am    
I build up a Class, and made a 1000 switch cases, I can not see any other way to reach my requirement. I have give up struct, because struct can not use the string name to access it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900