br4kejet
br4kejet
CC#
Created by Cubic on 4/18/2024 in #help
is there any way to make something be checked for every time a field is updated or do i need to use
In the same CurrentEnergy setter, you can then check if the new value equals the max energy, and if so, increment output by Phase3()
16 replies
CC#
Created by Cubic on 4/18/2024 in #help
is there any way to make something be checked for every time a field is updated or do i need to use
You should probably check the new value of CurrentEnergy before actually updating it. Setting a value in a property getter is typically a nono
16 replies
CC#
Created by stigzler on 3/31/2024 in #help
Refactor this if statement without an additional method
This is one way I find myself doing a lot:
KryptonWorkspaceCell? cell = SpaceControl?.ActiveCell;
bool hasZeroPages = false;
if (cell == null || (hasZeroPages = cell.Pages.Count() == 0))
{
if (hasZeroPages)
SpaceControl!.Root.Children!.Remove(cell)

cell = new KryptonWorkspaceCell();
SpaceControl!.Root.Children!.Add(cell);
}
KryptonWorkspaceCell? cell = SpaceControl?.ActiveCell;
bool hasZeroPages = false;
if (cell == null || (hasZeroPages = cell.Pages.Count() == 0))
{
if (hasZeroPages)
SpaceControl!.Root.Children!.Remove(cell)

cell = new KryptonWorkspaceCell();
SpaceControl!.Root.Children!.Add(cell);
}
23 replies
CC#
Created by Pandetthe on 3/20/2024 in #help
Find popup window in Wpf
You could use reflection to access the Window._showingAsDialog field, then iterate it using Application.Current.Windows.Cast<Window>().Where(x => x.Parent == targetParenttWindow && IsOpenedAsDialog(x))
6 replies
CC#
Created by TheUnquiet on 3/19/2024 in #help
Update an enum in a child class
The thing about OOP is sometimes you have to redefine the same properties for different classes because extending a base class isn't really possible, and if you ever run into that, you might have to use some sort of composition class that contains those properties that can be shared across different types. You might not run into it, but it's an annoying thing to deal with when using complicated inheritance 😛
42 replies
CC#
Created by TheUnquiet on 3/19/2024 in #help
Update an enum in a child class
Yeah
42 replies
CC#
Created by TheUnquiet on 3/19/2024 in #help
Update an enum in a child class
Then the oil and gas tankers derive from that class, and then you could do what you're doing now where the oil and gas tankers have their own enum things
42 replies
CC#
Created by TheUnquiet on 3/19/2024 in #help
Update an enum in a child class
like BaseTanker
42 replies
CC#
Created by TheUnquiet on 3/19/2024 in #help
Update an enum in a child class
Or create a class between Containerschip and the oil/gas tanker classes that has those properties like lengths, voluime, etc.
42 replies
CC#
Created by TheUnquiet on 3/19/2024 in #help
Update an enum in a child class
Having your oil tanker class derived from the gas tanker class seems a bit odd though, would it not be better to make them both extend Containerschip?
42 replies
CC#
Created by TheUnquiet on 3/19/2024 in #help
Update an enum in a child class
I've never seen this type of enum usage where each derived class has its own publicly exposed set of enum properties. I would just use something like a string in this case
42 replies
CC#
Created by TheUnquiet on 3/19/2024 in #help
Update an enum in a child class
You could check the range in the constructors but that gets weird for the base class constructors
42 replies
CC#
Created by TheUnquiet on 3/19/2024 in #help
Update an enum in a child class
public enum Lading
{
LPG,
LNG,
amoniak,
Olie,
Benzeen,
Desel,
Nafta
}
public enum Lading
{
LPG,
LNG,
amoniak,
Olie,
Benzeen,
Desel,
Nafta
}
42 replies
CC#
Created by TheUnquiet on 3/19/2024 in #help
Update an enum in a child class
Yeah, or merge all the values of the different Lading enums
42 replies
CC#
Created by TheUnquiet on 3/19/2024 in #help
Update an enum in a child class
I would probably use a string to represent that value instead of an enum
42 replies
CC#
Created by kettlemug on 3/14/2024 in #help
Making a field eligible for GC
That will probably result in a GC
6 replies
CC#
Created by kettlemug on 3/14/2024 in #help
Making a field eligible for GC
Maybe try create a new list with a million (boxed) long values, then sum them all and print to console (to ensure it won't get JIT'd out)
6 replies
CC#
Created by kettlemug on 3/14/2024 in #help
Making a field eligible for GC
If it's anything like java then Collect is just a hint, it might not actually collect and it might not collect everything (it might decide to collect things in gen0, but _entities might be in gen1 or gen2 because it's a field)
6 replies
CC#
Created by br4kejet on 3/10/2024 in #help
Is volatile necessary when using a lock to read/write the variable?
I can't remember what C's was but i think it's something like if you access a volatile variable 3 times and write 2 times, it will always do exactly that and won't read/write any caches
14 replies
CC#
Created by br4kejet on 3/10/2024 in #help
Is volatile necessary when using a lock to read/write the variable?
C#'s one is just it prevents reordering of read/write operations and stops the variable being cached right?
14 replies