473,385 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 13793
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: DLP22192 | last post by:
I have the following single-line if statement that is evaluating true even though it shouldn't. I have never seen this before and I am concerned that this can happen in other areas of my code. ...
3
by: Colleyville Alan | last post by:
I am constructing a SQL command from a function. Some code builds the WHERE clause in a looping structure and passes that as an argument to the SQL-building function. But the results do not...
16
by: Puneet | last post by:
Hi ALL, I have a silly question... (may be) Can we write a single line C program whose output is the program itself? Is anybody know the answer please tell me. Puneet
4
by: J Swift | last post by:
I posted this question earlier but on the wrong usenet. I have a warning below that I need to suppress *warning C4018: '<' : signed/unsigned mismatch I searched google, Microsoft help and MSDN...
7
by: bclegg | last post by:
Hi, I have a Monitoring application that needs to output single line summaries to a local dot matrix printer loaded with line flow. ie. It will have exclusive use of the printer which is connected...
3
by: saad82 | last post by:
I want to be able to replace a single line in a large text file (several hundred MB). Using the cookbook's method (below) works but I think the replace fxn chokes on such a large chunk of text. For...
2
by: sk.rasheedfarhan | last post by:
Hi , I have to extract a xml file line by line. Here is my xml Step1: <category name= "name" guid="{guid}"state="enabled"> Step2: <rules> Step3: <rule name="rule name" guid="{guid}"...
1
by: Nethra | last post by:
Hi... I am trying a program which convert the multiline comment type in a program to single line comment type ie. /*have a nice day */ to //have a //nice day
2
by: =?Utf-8?B?Umljaw==?= | last post by:
How do I create a textbox with a single line border so when I type text in the box it will look like underlined?
1
by: vikastcser | last post by:
Hi All , I have a table where four rows are there and each row has two tds.one td is for label and two image icons and other td is used for keeping numeric values. I am able to accomodate digits...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.