猿问

内嵌警告控制(VS2005)有什么作用

<P>#pragma warning disable 618</P> <P>能否详细讲解下,这个起什么作用?</P>


问题补充: 程序完整例子 public static System.Collections.Specialized.NameValueCollection AppSettings { get { #pragma warning disable 618 return System.Configuration.ConfigurationSettings.AppSettings; #pragma warning restore 618 } }


慕仙森
浏览 504回答 2
2回答

HUWWW

应该是消除.net版本/代码过期警告用的吧~~在使用这个语句的时候2.0的编译器会提示推荐使用 ConfigurationManager这个来访问配置文件.

Cats萌萌

#pragma warning disable 618 表示从这一行开始,本文件内如果触发了编号为0618的警告的话,不要提示. #pragma warning restore 618 则与上一个相反,从此行以后继续提示相关的警告. 在MSDN Library的索引页输入CS0618即可找到对应的编译警告说明: Compiler Warning (level 2) CS0618 Error Message 'member' is obsolete: '****' A class member was marked with the Obsolete attribute, such that a warning will be issued when the class member is referenced. The following sample generates CS0618: // CS0618.cs // compile with: /W:2 using System; public class C { [Obsolete("Use newMethod instead", false)] // warn if referenced public static void m2() { } public static void newMethod() { } } class MyClass { public static void Main() { C.m2(); // CS0618 } }
随时随地看视频慕课网APP
我要回答