Why we cann't use var instead of double when I declare constants? | Sololearn: Learn to code for FREE!
+ 9

Why we cann't use var instead of double when I declare constants?

C#

3rd Jan 2019, 2:04 PM
ArkarHtun
ArkarHtun - avatar
9 Answers
+ 6
No, you can't use var while defining the constant. You should use any of other data-type while defining constant. Otherwise, you can use var too.
3rd Jan 2019, 2:47 PM
Raj Chhatrala
Raj Chhatrala - avatar
3rd Jan 2019, 4:06 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 9
Yes thank, I understand now .var keyword can chage but other data type will be used in constant declartion
3rd Jan 2019, 2:38 PM
ArkarHtun
ArkarHtun - avatar
+ 8
Yes,thank ."const" is keyword?
6th Jan 2019, 3:52 PM
ArkarHtun
ArkarHtun - avatar
+ 7
thank you
4th Jan 2019, 12:24 AM
ArkarHtun
ArkarHtun - avatar
+ 6
While we define constant, it is not required to be double. You can surely change data-type of constat variable. I made a simple example where I defined constat with 4 different data-types. https://code.sololearn.com/c7CUxrGvYkf6/?ref=app
3rd Jan 2019, 2:16 PM
Raj Chhatrala
Raj Chhatrala - avatar
+ 6
Thank
11th Jan 2019, 11:21 PM
ArkarHtun
ArkarHtun - avatar
+ 2
you want to declare a constant variable so use const keyword instead of var keyword
6th Jan 2019, 3:43 PM
Hafiz usama
+ 2
because the value assigned to constant cannot be changed,
11th Jan 2019, 6:31 PM
Festus Mutua Muasya
Festus Mutua Muasya - avatar