Can someone explain to me how/when/why to use const keyword, or it is just “a way to declare a constant variable”? If so, what’s the difference between this :
int x = 5;
and
const int x = 5;
Could you guys please give me an example?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
constmeans compile time constant. The expression value must be known at compile time.constmodifies "values".From news.dartlang.org,
if you use
const x = 5then variable x can be used in a const collection likeif you don’t use
const, and just usex = 5thenconst aConstCollection = const [x];is illegal.More examples from http://www.dartlang.org