© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
6 replies
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              
 };   
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ C# Arrays/Switch case help
C#CC# / help
3y ago
✅ Switch Case Not Executing Properly
C#CC# / help
3y ago