How to define and use (constant) const string in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main()
    {
        const string s1 = "c# ";
        const string s2 = "Java ";
 
        Console.WriteLine(s1 + s2);
 
        // s1 = "php"; // Error CS0131: The left-hand side of an assignment must 
                       // be a variable, property, or indexer 
    }
}


/*
run:

c# Java 

*/

 



answered Jan 1, 2017 by avibootz
edited Jun 19, 2025 by avibootz

Related questions

1 answer 142 views
142 views asked Nov 23, 2020 by avibootz
2 answers 176 views
1 answer 178 views
1 answer 118 views
1 answer 160 views
4 answers 438 views
438 views asked May 23, 2018 by avibootz
1 answer 178 views
...