各位大虾,小弟最近想写一个方法,方法的的声明我想是这样的,比如 public void Func(CustomType value){};但是我想在调用此方法时这样,this.Func("A" == "B");这样CustomType这个类我该怎么写啊?在线等啊,急!

解决方案 »

  1.   

    public void Func(bool value)
    {
        Func("A" == "B");
    }
      

  2.   

    泛型方法
    public static void Func<T>(T t) where T : new()
    {}
      

  3.   

    我主要是想在实现数据库中的Where条件,如下:
    public void Func(CustomType value)
    {
       string filter=value.ToString();
       string SQL="SELECT * FROM table WHERE "+filter;
    }
    而调用的时候,Func("A" == "B");第一个"A"我想是个数据库字段,第二个是值,
    这样Func(CustomType value)方法中的SQL变量就可以成为
    "SELECT * FROM table WHERE A= 'B' "
      

  4.   

    直接字符串类型string str="A='B'";
      

  5.   

    没看懂你意思,猜测这样?public string CreateWhere(Dictionary<string,string> filter)
    {
        string SQL = "SELECT * FROM table WHERE ";
        StringBuilder builder = new StringBuilder();
        foreach (string key in filter.Keys)
        {
            builder.Append(key + "='" + filter[key] + "'");
        }
        return SQL + builder.ToString();
    }
    //调用
    Dictionary<string, string> filter = new Dictionary<string, string>();
    filter.Add("姓名", "飞雪孤风");
    string sql_command = CreateWhere(filter);
      

  6.   

    // method 1 ?
    void Func(Predicate<DataRow> filter)
    {
       DataTable table = ExecSql("select * from table");
       foreach(DataRow row in table.Rows)
       {
          if(filter(row))
          {
              //...
          }
       }
    }// method 2 ?
    public void Func(string filter)
    {
      string filter=value.ToString();
      string SQL="SELECT * FROM table WHERE "+filter;
    }
      

  7.   

    CustomType得和select * 出来的字段一样然后直接把数据放在List<CustomType>里返回,SQL语句可以写成
    public List<CustomType > Func(String value)
    {
    if(filter!="")
    {
    string SQL="SELECT * FROM table WHERE 1=1 "+" and "+filter;
    }
    //...
    }
      

  8.   

    List<object>,Dictionary<object,object>保存条件遍历
    看看数据库操作类
      

  9.   

    7楼说的是点意思了,可是我不关是再调用的时候只用Func("A" == "B")啊,我还想用Func("A" >= "B")或者Func("A" <= "B")之类的操作符,还有类似的like '%%'这种模糊的Where条件该杂办啊?
      

  10.   

    9楼有点不明白意思,我是想问那个CustomType类该杂写,我觉得这个是个操作符重载的问题,不过还是有些里不清楚思路啊~!