Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# switch expression pattern matching

string startsWith = "somestring:";

 switch (startsWith)
 {
	 // Using the 'when' keyword you can convert your case to a bool like
     // expression like so:
     case string when startsWith.StartsWith("somestring:"):
         Console.WriteLine("hit");
         break;

   case string when startsWith.StartsWith("someotherstring:"):
		Console.WriteLine("hit 1");
		break; 
}

// Output: hit
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity script template folder 
Csharp :: unity normalize movement 
Csharp :: c# interface properties 
Csharp :: Severity Code Description Project File Line Suppression State Error MSB3021 
Csharp :: array sum c# 
Csharp :: oncollisionenter2d 
Csharp :: how to stop timer in c# windows application 
Csharp :: c# external execute batch 
Csharp :: c# list object 
Csharp :: runtime save scene unity 
Csharp :: fill dictionary c# 
Csharp :: c# WriteLine() 
Csharp :: dotnet create web api 
Csharp :: c# return multiple values 
Csharp :: get list of months and year between two dates c# 
Csharp :: c# reflection create generic type 
Csharp :: how to call a method from a class c# 
Csharp :: c# list empty 
Csharp :: how to add a ddos api to a c# console app 
Csharp :: Convert a string to Integer in C# without library function 
Csharp :: unity fast sin 
Csharp :: c# null accessor 
Csharp :: blazor conditional reenreing 
Csharp :: C# HttpUtility not found / missing C# 
Csharp :: Photon Register Callbacks 
Csharp :: asp net mvc convert ienumerable to selectlistitem 
Csharp :: c# datafield change cell background color 
Csharp :: How to create a gameobject by code 
Csharp :: AsExpandable 
Csharp :: c# registrykey is null 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =