Const vars
-
I want to make some variables contstant. This is the important part of the code:
namespace NiklasUlvinge.ChipsEater { abstract class Item { ... //const protected Brush surf = Brushes.LightGray; protected Pen side = Pens.DarkGray; protected Pen loff = Pens.Black; protected Pen lon = Pens.Red; ... } ... }
I want child's to Item to be able ot accsess those pens, and it would be better if they where constant. If I make the constant it give's me error like Pens.Red isn't a constant variable. How do I make them constant? Niklas Ulvinge aka IDK -
I want to make some variables contstant. This is the important part of the code:
namespace NiklasUlvinge.ChipsEater { abstract class Item { ... //const protected Brush surf = Brushes.LightGray; protected Pen side = Pens.DarkGray; protected Pen loff = Pens.Black; protected Pen lon = Pens.Red; ... } ... }
I want child's to Item to be able ot accsess those pens, and it would be better if they where constant. If I make the constant it give's me error like Pens.Red isn't a constant variable. How do I make them constant? Niklas Ulvinge aka IDK -
You don't. Objects can't be constants. You can make them static, though. --- b { font-weight: normal; }
Thanks, that's what I was looking for. Niklas Ulvinge aka IDK
-
I want to make some variables contstant. This is the important part of the code:
namespace NiklasUlvinge.ChipsEater { abstract class Item { ... //const protected Brush surf = Brushes.LightGray; protected Pen side = Pens.DarkGray; protected Pen loff = Pens.Black; protected Pen lon = Pens.Red; ... } ... }
I want child's to Item to be able ot accsess those pens, and it would be better if they where constant. If I make the constant it give's me error like Pens.Red isn't a constant variable. How do I make them constant? Niklas Ulvinge aka IDKMake them
readonly
. That way, no one else can do surf = Brushes.Yellow or something like that. Regards Senthil _____________________________ My Blog | My Articles | WinMacro -
Make them
readonly
. That way, no one else can do surf = Brushes.Yellow or something like that. Regards Senthil _____________________________ My Blog | My Articles | WinMacroNow it is: readonly static protected Brush surf = Brushes.LightGray; Isn't that the same as a const, Readonly and only belongs to the type? Niklas Ulvinge aka IDK