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 245 views
1 answer 218 views
218 views asked Nov 23, 2020 by avibootz
1 answer 239 views
1 answer 264 views
264 views asked Apr 28, 2016 by avibootz
1 answer 253 views
1 answer 224 views
1 answer 224 views
...