Home
Blogs
Questions
Jobs
Monetize

Home

About Us

Blogs

Questions

Jobs

Monetize

Post Job

banner

Questions about switch-expression

Read more about switch-expression

python (65.2k questions)

javascript (44.3k questions)

reactjs (22.7k questions)

java (20.8k questions)

c# (17.4k questions)

html (16.3k questions)

r (13.7k questions)

android (13k questions)

Questions - switch-expression

Why can't return be expressed in one line when using a Switch Expression?

while (true) { console.mainMenu(); String inputCommand = console.input(); switch(inputCommand) { case "exit" -> return; case "create" -> { ...
test-img

yongc

java

return

expression

java-14

switch-expression

Votes: 0

Answers: 1

Latest Answer

You can't use a statement as a rule (the part after the arrow ->) in a switch expression. It must be either an expression or block (which can contain a statement or multiple statements) These are v...
test-img

Alexander Ivanchenko

C# Pattern match arrays

var x = new int[] { 1, 2 }; var y = x switch { { 1, 2 } => "yea", _ => "nay" }; fails to compile. How can I pattern-match arrays?
test-img

theonlygusti

c#

pattern-matching

switch-expression

Votes: 0

Answers: 1

Latest Answer

You have to expand the elements of the array yourself like so var x = new int[] { 1, 2 }; var y = (x[0], x[1]) switch { (1, 2) => "yea", _ => "nay" };
test-img

John Glenn

Posts

Questions

Blogs

Jobs

The ultimate platform for coders and IT specialists

About

  • Company
  • Support

  • Platform

  • Terms & Conditions
  • Privacy statement
  • Cookie policy
  • Cookie option
  • OnlyCoders © 2025  |  All rights reserved