C
C#2y ago
SWEETPONY

✅ Is it possible to write better switch/case?

I have following:
_ = delivery.Topic switch
{
_ when delivery.Topic.Contains( "event" )
=> Brush.Color = Colors.Yellow,
_ when delivery.Topic.Contains( "command" )
=> Brush.Color = Colors.Green,
_ => Brush.Color = Colors.Beige
};
_ = delivery.Topic switch
{
_ when delivery.Topic.Contains( "event" )
=> Brush.Color = Colors.Yellow,
_ when delivery.Topic.Contains( "command" )
=> Brush.Color = Colors.Green,
_ => Brush.Color = Colors.Beige
};
6 Replies
SWEETPONY
SWEETPONYOP2y ago
I think _ looks a little bit ugly.. How I can improve my code?
jcotton42
jcotton422y ago
just use if
Jimmacle
Jimmacle2y ago
kind of an abuse of a switch expression if you ask me
jcotton42
jcotton422y ago
instead of... that
Jimmacle
Jimmacle2y ago
you're discarding all the parts that make that syntax useful
SWEETPONY
SWEETPONYOP2y ago
yeah, ur right I will rewrite my code
Want results from more Discord servers?
Add your server