How to declare constant (const) in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        const int X = 20;

        Console.Write(X);
        
        // error CS0131: The left-hand side of an assignment must be a variable, 
        //               a property or an indexer
        // X = 11;
    }
}



/*
run:

20

*/

 



answered Nov 23, 2020 by avibootz

Related questions

1 answer 165 views
1 answer 125 views
125 views asked Nov 23, 2020 by avibootz
1 answer 161 views
1 answer 165 views
165 views asked Apr 28, 2016 by avibootz
1 answer 122 views
1 answer 130 views
1 answer 123 views
...