问题描述
我从这里的绅士那里得到了一个使用
以下语法的提示。
public static FileInfo []
GetFilesRegExp(此DirectoryInfo di,字符串pat)
{
正则表达式re =新正则表达式(pat);
返回Array.FindAll (
di.GetFiles(),
(f)= re.IsMatch(f.Name));
}
问题是编译器似乎不喜欢
this在参数列表中以及在lambda表达式中转到
。
这是怎么回事?如何杀死它?
-
问候
Konrad Viltersten
-------- --------------------------------
愿所有垃圾邮件发送者死于痛苦的死亡;
没有埋葬地点;他们的灵魂会被Gehenna的恶魔从一个房间追逐
到另一个房间,永远和超越。
I''ve got a hint from a gentleman here to use the
following syntax.
public static FileInfo[]
GetFilesRegExp(this DirectoryInfo di, string pat)
{
Regex re = new Regex(pat);
return Array.FindAll(
di.GetFiles(),
(f) =re.IsMatch(f.Name));
}
The problem is that the compiler seems to dislike
"this" in the argument list as well as "goes to"
in the lambda expression.
What''s up with that and how do i kill it?
--
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.
推荐答案
你得到什么错误_exactly_。编写编译器似乎
不喜欢根本没有解释你的问题。
就这个而言,我希望你没有使用C#3.0或
你试图在非静态类中声明该方法。但是没有
知道错误,很难确定哪一个或两个是否正确。
我没有看到lambda表达式有任何明显错误,但是再次...... / b $ b ...如果你没有使用C#3.0,那么它就行不通了。
了解实际的错误消息有助于_lot_。坦率地说,如果你在编译或执行过程中询问有关出现错误的帮助,那么'
总是如此。
Pete
What errors are you getting _exactly_. Writing "the compiler seems to
dislike" doesn''t explain your problem at all.
As far as the "this", I expect that either you''re not using C# 3.0 or
you''re trying to declare the method in a non-static class. But without
knowing the error, it''s hard to say for sure which or whether either is
correct.
I don''t see anything obviously wrong with the lambda expression, but
again...if you''re not using C# 3.0, then it wouldn''t work.
Knowing the actual error message would help a _lot_. Frankly, that''s
always going to be true if you are asking about help with errors that
occur, either during compilation or execution.
Pete
你得到什么错误_exactly_。编写编译器似乎
不喜欢根本没有解释你的问题。
就这个而言,我希望你没有使用C#3.0或
你试图在非静态类中声明该方法。但是没有
知道错误,很难确定哪一个或两个是否正确。
我没有看到lambda表达式有任何明显错误,但是再次...... / b $ b ...如果你没有使用C#3.0,那么它就行不通了。
了解实际的错误消息有助于_lot_。坦率地说,如果你在编译或执行期间询问有关出现错误的帮助,那么'
总是如此。
What errors are you getting _exactly_. Writing "the compiler seems to
dislike" doesn''t explain your problem at all.
As far as the "this", I expect that either you''re not using C# 3.0 or
you''re trying to declare the method in a non-static class. But without
knowing the error, it''s hard to say for sure which or whether either is
correct.
I don''t see anything obviously wrong with the lambda expression, but
again...if you''re not using C# 3.0, then it wouldn''t work.
Knowing the actual error message would help a _lot_. Frankly, that''s
always going to be true if you are asking about help with errors that
occur, either during compilation or execution.
我可以说我提供了足够的信息,我的
有用的朋友。事实上,我使用的是v2.0,在你指出它之前,我并没有意识到这一点。万分感谢!
(当然,我同意你的意见 - 一个人应该总是
提供错误信息。在这种情况下,我知道了吗
不可能。但是,为了将来参考,我会做的。)
现在,我确信安装了VS 2008升级版我的
框架到v3.5。显然,它没有......升级
到最新版本的框架是免费的,如果
我已经付费版本了VS2005?
-
问候
Konrad Viltersten
------- ---------------------------------
愿所有垃圾邮件发送者死于痛苦的死亡;
没有埋葬地点;他们的灵魂将来自Gehenna的恶魔从一个房间被追逐
到另一个房间永恒和超越。
I could argue that i provided just enough information, my
helpful friend. In fact, i was using v2.0, which i wasn''t
aware of until you pointed it out. Thanks a million!
(Of course, i agree with you - one should almost always
provide the error messages. In this case, i KNEW it
couldn''t be that. However, for future reference, i''ll do it.)
Now, i was sure that installing VS 2008 upgraded my
framework to v3.5. Obviously, it didn''t... Is the upgrade
to the latest version of the framework free of charge if
i''m already on a paid version of VS2005?
--
Regards
Konrad Viltersten
----------------------------------------
May all spammers die an agonizing death;
have no burial places; their souls be
chased by demons in Gehenna from one room
to another for all eternity and beyond.
我可以说我提供了足够的信息,我的
有用的朋友。
I could argue that i provided just enough information, my
helpful friend.
嗯,你可以争论任何你喜欢的东西。这并不意味着你是对的。
:)
Well, you can argue anything you like. That doesn''t mean you''d be right.
:)
C#2.0?还是.NET 2.0?
C# 2.0? Or .NET 2.0?
如果您使用的是VS 2008,那么您使用的是C#3.0。在VS 2008中,项目可以从2.0开始针对任何特定版本的.NET。默认应该是
..NET 3.5,但你要问的问题是语言/编译器问题
所以即使你意外地针对早期版本的.NET,使用VS
2008应该仍然允许它编译。相反,只安装.NET
3.5 SDK是不够的。你需要使用支持C#3.0功能的编译器
,这是VS 2008.
换句话说,我们回到了我以前的评论:如果不知道
确切的错误信息,就不可能确定问题是什么。
_If_我对语言版本的评论有引导你到一个实际的
解决方案,然后_maybe_你可以试着争辩说你已经提供了足够的
信息(但我会争辩说我是好猜测:))。但是,如果你没有解决问题,即使我已经给出了答案,
显然你还没有提供足够的信息来回答问题
呢。 :)
Pete
If you''re using VS 2008, you''re using C# 3.0. In VS 2008, projects can
target any specific version of .NET from 2.0 on. The default ought to be
..NET 3.5, but the issues you''re asking about are language/compiler issues
so even if you accidently targeted an earlier version of .NET, using VS
2008 should still allow it to compile. Conversely, just having the .NET
3.5 SDK installed isn''t sufficient. You need to be using the compiler
that supports C# 3.0 features, which is VS 2008.
In other words, we''re back to my previous comment: without knowing the
exact error message, it''s impossible to say for sure what the problem is.
_If_ my comments about language version have led you to an actual
solution, then _maybe_ you can try to argue that you''ve provided enough
information (but I''ll just argue I''m a good guesser :) ). But if you
haven''t solved the problem yet even with the answer I''ve given so far,
obviously you haven''t provided enough information to answer the question
yet. :)
Pete
这篇关于编译lambda表达式的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!