I
I
INTERNALINTERFERENCE2021-11-04 15:54:39
C++ / C#
INTERNALINTERFERENCE, 2021-11-04 15:54:39

How to compare tuples in C#?

in rast I can write like this:

fn main() {
  
    let user = ("Bob", 37);
    match user{
        ("Tom", 36) => println!("name: Tom, age: 36"),
        ("Bob", 37) => println!("name: Bob, age: 37"),
        _ => println!("Undefined")
    }
}


what is the syntax in sharps? I know what it is exactly, but I can’t remember and find it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ayazer, 2021-11-04
@INTERNALINTERFERENCE

https://docs.microsoft.com/en-us/dotnet/csharp/fun...

var user = ("Bob", 37);

var str = user switch {
  ("Tom", 36) => "name: Tom, age: 36",
  ("Bob", 37) => "name: Bob, age: 37",
  _ => "Undefined"
}

Console.Writeline(str);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question