What will be the error in the following C# code? [code] Static Void Main(String[] args) { const int m = 100; int n = 10;

What will be the error in the following C# code?
Code:
 Static Void Main(String[] args)
 {
     const int m = 100;
     int n = 10;
     const int k = n / 5 * 100 * n ;
     Console.WriteLine(m * k);
     Console.ReadLine();
 }
A. ‘k’ should not be declared constant
B. Expression assigned to ‘k’ should be constant in nature
C. Expression (m * k) is invalid
D. ‘m ‘ is declared in invalid format
 
Answer: b
Explanation:’k’ should be declared as const int k = 10/5 * 100*10 i.e only constant values should be assigned to a constant.
Output:
Code:
Error 1 - The expression being assigned to 'k' must be constant.
 

Tìm kiếm

Back
Top