No matter what I Google, there doesn't seem to be an answer for this! In a C# class, what does the new keyword do to a const field?
e.g:
private const int ConstOne = 0;
private new const int ConstTwo = 0;
It is recommended to use const constructors whenever possible when creating Flutter widgets. The reason is the performance increase, since Flutter can save some calculations by understanding that it can reuse that widget from a previous redraw in the current one, since it is a constant value.
const means its initial value is must be fixed, can not be a dynamic value; final means its initial value is must be fixed but can be a dynamic value, equal to the var with a fixed value.
The const declaration creates a read-only reference to a value. It does not mean the value it holds is immutable—just that the variable identifier cannot be reassigned. For instance, in the case where the content is an object, this means the object's contents (e.g., its properties) can be altered.
A variable with the const keyword is initialized at compile-time and is already assigned when at runtime. You can't define const inside a class.
The new
keyword is used when hiding a member from a base class.
It doesn't actually do anything; it just tells the compiler not to warn you that you're hiding the base field.
See the documentation
The new keyword is used when hiding a member. It works for all class members like methods, fields, etc.
Basically hiding is used to declare that you know that you are going to hide a member and are aware that it is not going to be used in polymorphic scenarios unlike when you are overriding a member.
Google for hiding vs overriding. For example: http://www.akadia.com/services/dotnet_polymorphism.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With