怎么把字符串中的内容当一个表达式或程序中的一行用。
比如
    1、string s="this.Close()"    
    怎么 s 执行 this.Close();在比如
   2、  var bindingSource1=from p in DB.Clinet where  id==111||id==222||id==333 select p
有如下的方法实现2、的效果
    string str="id==111||id==222||id==333 ";  //用一定的方法实现str
   var bindingSource1=from p in DB.Clinet where  str   p   //怎么让str 实现 2、的效果
  

解决方案 »

  1.   

    我找到答案了,谁有好的方案可以在说下;和下面的类似
       static void Main()
        {
            // Data source
            int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };        // Create the query with a method call in the where clause.
            // Note: This won't work in LINQ to SQL unless you have a
            // stored procedure that is mapped to a method by this name.
            var queryEvenNums =
                from num in numbers
                where IsEven(num)
                select num;         // Execute the query.
            foreach (var s in queryEvenNums)
            {
                Console.Write(s.ToString() + " ");
            }
        }    // Method may be instance method or static method.
        static bool IsEven(int i)
        {
            return i % 2 == 0;
        }    
    }
    //Output: 4 8 6 2 0
      

  2.   

    没用,你的IsEven只能返回bool,不能返回string
      

  3.   

    哎上面的方法不支持 sql 转换啊。
     那个高人知道,用那个.net的可以做 到比较2个 字符串数组 str_Arr1、str_Arr2 如果有1个字符串相同就返回真,没有返回假。
      

  4.   

    靠 微软的自己的也不支持linq to sql 的sql转换 str_Arr.Contains (p.TypeId )
    bindingSource1.DataSource  = from p in DB_ClientInfo.ClientInfo where str_Arr.Contains (p.TypeId ) select p;