如何在静态结构集合中查找指定的数据? [英] How to find specified data in a static struct collection?

查看:62
本文介绍了如何在静态结构集合中查找指定的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生:

我遇到一个问题,我为数据系统编写了一个程序,由于某些限制,我不想使用ADO.NET和Access MDB,我做了一个结构如下:

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:

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);

  }


我将talbe做成struct,将一个表转换为一个struct,也许有200个或更多表,每个表有300条或更多记录.这些表都在DataLib类中.
问题是如何找到指定的表,然后在tablename[]中找到指定的数据?

例如:
String xxx; string yyy;
我想查找名称等于xxx的表,并在xxx []中找到table.g2 = yyy,并枚举每个字段哪个未知?我该怎么办?

谢谢.
david jang


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

推荐答案

签出 LINQ to Objects [ ^ ],以及可以 [
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);
}


这篇关于如何在静态结构集合中查找指定的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆