Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Const
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { const int x=10; //value must be initialized const int y=100; int j=101; public Program() { const int z=x+y; // no error, both x and y must define with const. we get error when any of x or y non const to assign const z const int i=j; // error, here j is not const,it's only with int data type but i can take value from only const. int k=y; // no error, here y is const to assign int data type k varaible. Console.WriteLine(z); Console.WriteLine(i); Console.WriteLine(k); } public Program(int xyz) //error, because const can take values only when declaration not at runtime. { const x=xyz; Console.WriteLine(x); } public static void Main(string[] args) { //Your code goes here Console.WriteLine("Hello, world!"); Program p=new Program(); Program p1=new Program(101); } } }
run
|
edit
|
history
|
help
0
C++
gggsggsgg
Square Real Matrix
Day1
Cs
Two lines of Random number
asdfrgthyu6543wdsc
6.4 Parallelism: threads and events
Find duplicates in a given integer array
cte-like constructs in C#