关于C#编译器错误CS0685(VS2005)
2007-05-25 22:38 晓风残月 阅读(993) 评论(1) 编辑 收藏 举报
今天CSDN中有人发现Duwamish7(C#)升级到VS2005后,SystemFramework编译通不过了,尝试了一下果然报错:
呀呀,不会吧,当年VS2003的时候 Duwmish 7我可是研究过千百回了(夸张了点,其实没研究透:->),都没有出现过这个错误,不知道C# complier 那根筋接错了神经线老
查了MSDN,原来这个编译错误编码为 CS0685,描述如下:
看来,确实不能为具有out 参数的方法,使用 ConditionAttribute 属性。但是,不知道,VS2003如何能编译通过,没有 03 环境也无法验证了。
update 2007年5月26日 在 1.x 下重新测试一下,确实可以编译通过!
懒得装VS2003,就装了个 .net framework 1.1,命令行中调用 csc,编译如下代码:
输出如下:
顺便测试了 ref 参数,在.net 1.1 和 .net 2.0 下均编译OK!
[ConditionalAttribute("DEBUG")]
private static void GenerateStackTrace2(int lineNumber, ref String currentTrace)
{
}
呀呀,不会吧,当年VS2003的时候 Duwmish 7我可是研究过千百回了(夸张了点,其实没研究透:->),都没有出现过这个错误,不知道C# complier 那根筋接错了神经线老
查了MSDN,原来这个编译错误编码为 CS0685,描述如下:
编译器错误 CS0685
错误消息
条件成员“member”不能有 out 参数
在方法上使用 ConditionalAttribute 属性时,该方法不能有 out 参数。这是因为,如果方法调用编译为 nothing,则不会定义用于 out 参数的变量的值。若要避免此错误,请将 out 参数从条件方法声明中移除,或者不使用条件属性。
http://msdn2.microsoft.com/zh-cn/library/kykzee2e(vs.80).aspx错误消息
条件成员“member”不能有 out 参数
在方法上使用 ConditionalAttribute 属性时,该方法不能有 out 参数。这是因为,如果方法调用编译为 nothing,则不会定义用于 out 参数的变量的值。若要避免此错误,请将 out 参数从条件方法声明中移除,或者不使用条件属性。
看来,确实不能为具有out 参数的方法,使用 ConditionAttribute 属性。但是,不知道,VS2003如何能编译通过,没有 03 环境也无法验证了。
update 2007年5月26日 在 1.x 下重新测试一下,确实可以编译通过!
懒得装VS2003,就装了个 .net framework 1.1,命令行中调用 csc,编译如下代码:
class ConditionalAttributeTest
{
static void Main(string[] args)
{
string msg = null;
MethodUsingOutParamWithConditionalAttribute(out msg);
Console.WriteLine(msg);
}
[ConditionalAttribute("DEBUG")]
private static void MethodUsingOutParamWithConditionalAttribute(out string msg)
{
msg =
"The ConditionalAttribute attribute can be used on a method that has an out parameter \n" +
"under Microsoft .NET Framework version " + System.Environment.Version.ToString();
}
}
{
static void Main(string[] args)
{
string msg = null;
MethodUsingOutParamWithConditionalAttribute(out msg);
Console.WriteLine(msg);
}
[ConditionalAttribute("DEBUG")]
private static void MethodUsingOutParamWithConditionalAttribute(out string msg)
{
msg =
"The ConditionalAttribute attribute can be used on a method that has an out parameter \n" +
"under Microsoft .NET Framework version " + System.Environment.Version.ToString();
}
}
输出如下:
顺便测试了 ref 参数,在.net 1.1 和 .net 2.0 下均编译OK!
[ConditionalAttribute("DEBUG")]
private static void GenerateStackTrace2(int lineNumber, ref String currentTrace)
{
}