为什么我的LINQ表达式不起作用? [英] Why my LINQ expression does not work?

查看:64
本文介绍了为什么我的LINQ表达式不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有趣的是,它适用于一个项目,但另一个项目不起作用!我为这两个项目使用Visual Studio 2008.

It is interesting to say it works for one project but for another it doesn't work! I use Visual Studio 2008 for the both projects.

if (str.Substring(0, "@variable".Length) != "@variable" && str.Substring(0, "@composite".Length) != "@composite")
            {

                s = str.Split('.')[0];

                tablesList.Add(s);

            }

        }

        List<string> distinctItem = tablesList.Distinct().ToList();

        List<string> globalTablesList = GetTableNames(dt);

        List<string> commonTableList = (from item in distinctItem
                                        where globalTablesList.Contains(item)
                                        select item).ToList();



显示的错误:


The errors shown:



  1. )预期D:\ BIPORTAL-Dev\App_Code\Service.cs 162 46 D:\ BIPORTAL-Dev \

  2. 无效的表达式术语'在'D:\ BIPORTAL-Dev \ App_Code \ Service.cs 162 51 D:\ BIPORTAL-Dev \

  3. ;预期D:\ BIPORTAL-Dev \ App_Code \ Service.cs 162 51 D:\ BIPORTAL-Dev \

推荐答案

检查两个项目属性。

猜测,你会发现它工作的项目被设置为.NET版本V3.5,并且它没有设置为.NET V3.0或更低版本。



Linq语法在V3.5中引入,因此早于此版本的版本不支持它。



BTW:你的如果代码有点奇怪:你确实意识到字符串类有一个< a href =http://msdn.microsoft.com/en-us/library/system.string.startswith(v=vs.110).aspx> StartsWith [ ^ ]方法?

Check the two project properties.
At a guess, you will find that the project where it works is set as .NET version V3.5, and the one where it doesn't is set as .NET V3.0 or below.

Linq syntax was introduced at V3.5, so versions earlier than that do not support it.

BTW: your if code is a bit weird: you do realize that the string class has a StartsWith [^]method?
if (!str.StartsWith("@variable") && !str.Startswith("@composite"))
   {
   s = str.Split('.')[0];
   tablesList.Add(s);
   }


这篇关于为什么我的LINQ表达式不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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