Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7968985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:09:50+00:00 2026-06-04T07:09:50+00:00

When compiling the following program in VS2010, VS2008 or MonoDevelop on Windows, I get

  • 0

When compiling the following program in VS2010, VS2008 or MonoDevelop on Windows, I get warning CS0219, “The variable ‘y’ is assigned but its value is never used”.

namespace Problem
{
    public class Program
    {        
        private static void Main(string[] args)
        {
            object x = new object();
            int y = 0;
        }
    }
}

Why is there no warning for x when compiling in Visual Studio?

Interestingly, I do get CS0219 warnings for x and y when compiling in MonoDevelop on Mac OS X.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:09:52+00:00Added an answer on June 4, 2026 at 7:09 am

    It turns out that this warning is suppressed when the right-hand-side of the assignment operation is not a compile-time constant.

    A since-deleted post on Microsoft’s Visual Studio feedback site explained that it’s because they had lots of complaints from people who were assigning variables purely so they could see what a method call returned during debugging, and found the warning irritating:

    The suppression of the “assigned but never used” warning in this case
    was motivated by feedback from users who do this:

    int Blah(){
        // blah
        BlahBlah(x, y, z)
        // blah
        // blah
    }
    

    “Hey,” says the user while debugging, “I wonder what BlahBlah is
    returning?” But there is no easy way to examine the return value in
    the debugger, so users very frequently do this:

    int Blah()
    {
        // blah
        int temp = BlahBlah(x, y, z)
        // blah
        // blah
    }
    

    and then use the locals or watch window to examine temp. The temp is
    never used anywhere else in the function, so it produced an irritating
    “assigned but not read” warning.

    I think this is a bit of a shame since:

    1. I actually find these warnings helpful when they are given in MonoDevelop.
    2. Anyone can suppress the warning themselves (admittedly they’d also be suppressing the ones for unused compile-time constant assignments – maybe there should be a separate warning for that?).

    Anyway, I understand that you can’t please everyone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

when compiling my program with GCC I get the following warning: format ‘%d’ expects
Compiling with gcc 4.4.3 on Ubuntu 10.04.2 x86_64 I get the following warning: warning:
I get the following error with a Windows file when compiling winbase.h . Not
I'm having problems compiling the following program. I'm using gcc -framework Foundation inherit8.1m and
Will the following program cause any problem during compiling and execution process? class A{
Consider the following C program, 'pause.c': void main() { pause(); } Compiling this on
I am getting the following error while compiling a sample program in Qt 4.5
I'm trying to overload the dereference operator, but compiling the following code results in
I get the following error compiling with make (I have cygwin.dll) *** Couldn't reserve
The following code snippet generates some warning messages when compiling: Cluster& Myclass::getCluster(const Point &p)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.