469,898 Members | 2,033 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Suppress warning from a single line

I want to suppress the following warning when compiling.
warning CS0169: The private field 'myvar' is never used

In C++ you would do something like (not sure of the syntax):
#pragma nowarn:0169
string myvar;
#pragma warn:0169

Is this really still not possible in C#?
I know you can set the /nowarn:0169 option in you project, but I do not want
to disable it for everything in the project..
I just want to disable it from that one line until 'myvar' gets implemented.
Nov 17 '05 #1
6 12977
Kim,

You can not do this in C#, you will have to disable the warning.

Of course, the warnings are there for a reason, and the fix is simple
for your particular warning, so it's probably better that you code the
variable declaration the right way.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kim Hellan" <so*****@nowhere.com> wrote in message
news:e5*************@TK2MSFTNGP12.phx.gbl...
I want to suppress the following warning when compiling.
warning CS0169: The private field 'myvar' is never used

In C++ you would do something like (not sure of the syntax):
#pragma nowarn:0169
string myvar;
#pragma warn:0169

Is this really still not possible in C#?
I know you can set the /nowarn:0169 option in you project, but I do not
want to disable it for everything in the project..
I just want to disable it from that one line until 'myvar' gets
implemented.

Nov 17 '05 #2

"Kim Hellan" <so*****@nowhere.com> wrote in message news:e5*************@TK2MSFTNGP12.phx.gbl...
I want to suppress the following warning when compiling.
warning CS0169: The private field 'myvar' is never used

In C++ you would do something like (not sure of the syntax):
#pragma nowarn:0169
string myvar;
#pragma warn:0169

Is this really still not possible in C#?


Sure it is. The syntax is far simpler as well (actually, you can do the same thing in C++)
just change
string myvar;
to
// string myvar;

There...problem solved.

OK, I am joking around a bit, but really, why not just comment it out until you are ready to use it?

No, really, I am sure you will have thought of commenting it out considering the depth of solution
you have persued.
What is wrong with the comment?

Bill
Nov 17 '05 #3
Surer Kim. Use:

#pragma warning disable
#pragma warning restore

You can also use this directive with a comma-delimited list of warning
numbers. Example:

#pragema warning disable 0169

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.

"Kim Hellan" <so*****@nowhere.com> wrote in message
news:e5*************@TK2MSFTNGP12.phx.gbl...
I want to suppress the following warning when compiling.
warning CS0169: The private field 'myvar' is never used

In C++ you would do something like (not sure of the syntax):
#pragma nowarn:0169
string myvar;
#pragma warn:0169

Is this really still not possible in C#?
I know you can set the /nowarn:0169 option in you project, but I do not
want to disable it for everything in the project..
I just want to disable it from that one line until 'myvar' gets
implemented.

Nov 17 '05 #4
Kevin Spencer <ke***@DIESPAMMERSDIEtakempis.com> wrote:
Surer Kim. Use:

#pragma warning disable
#pragma warning restore

You can also use this directive with a comma-delimited list of warning
numbers. Example:

#pragema warning disable 0169


Note that (as far as I can tell) this is for C# 2.0 only. It certainly
doesn't seem to work with the 1.1 compiler. (Interestingly enough, I
couldn't find it in my printed copy of the C# 2.0 spec I was looking at
earlier...)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #5
Darn, Jon! Most of the time I look in the correct version of the MSDN
library, but the one I use the most is the 2.0 version. I can assure you,
though, at least in .Net 2.0, it's there!

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Kevin Spencer <ke***@DIESPAMMERSDIEtakempis.com> wrote:
Surer Kim. Use:

#pragma warning disable
#pragma warning restore

You can also use this directive with a comma-delimited list of warning
numbers. Example:

#pragema warning disable 0169


Note that (as far as I can tell) this is for C# 2.0 only. It certainly
doesn't seem to work with the 1.1 compiler. (Interestingly enough, I
couldn't find it in my printed copy of the C# 2.0 spec I was looking at
earlier...)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Nov 17 '05 #6
Kevin Spencer <ke***@DIESPAMMERSDIEtakempis.com> wrote:
Darn, Jon! Most of the time I look in the correct version of the MSDN
library, but the one I use the most is the 2.0 version. I can assure you,
though, at least in .Net 2.0, it's there!


Yup - I checked that it would work with 2.0 (at least the beta 2). I'm
still surprised I couldn't find it in the language spec though. Must
have a closer look tomorrow...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by DLP22192 | last post: by
3 posts views Thread by Colleyville Alan | last post: by
4 posts views Thread by J Swift | last post: by
3 posts views Thread by saad82 | last post: by
2 posts views Thread by sk.rasheedfarhan | last post: by
2 posts views Thread by =?Utf-8?B?Umljaw==?= | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.