Why does this program generate only three warnings?

public class Program
{
     public static void main(String[] args)
     {
         string message = "This is a message";
         int number = 6;
         object obj = null;
         int? nullable = (int?)12;
     }
}

The first three variable declarations in this program raise the following warning:

The variable "X" is assigned, but its value is never used.

However, the last statement:

int? nullable = (int?)12;

throws nothing. Why is this?

enter image description here

+4
source share
3 answers

, , , , , , - . , null , , . ; , , , - , - . , ( , ), .

+4

, . , , , , . , .

- , . , :

number += nullable;

1 . - :

message = message + " and this is more message";

.

, int? , , , . , , , , , - .

, - :

var a = new SomeClass();
var b = a;

, a, . , .

0

, , . , number. , . - "". , , , ( "" )

class Program
{
    static void Main(string[] args)
    {
        string message = ';'.ToString();
        int number = 6;
        object obj = (object)(new t());
        int? nullable = (int?)12;
    }
    class t
    { }
}

. , int '12' int?. , " ", .

0
source

Source: https://habr.com/ru/post/1607021/


All Articles