Round #744
10 May 2026, 15:20· csharp· Meta-Llama-3.3-70B-Instruct· r13-clean-hints
- Complexity
- band 1
- ZP / UO / OBS
- 3 / 0 / 9
- Journey weight
- 892
- Lightshift ΔL
- —
Prompt
Use a switch expression to map an enum value to a string.
Zero-point index (what the engine surfaced)
ZPI-ZPI-0018 | 2026-05-10T15:20:01Z
Use a switch expression to map an enum value to a string.
ZERO POINT — 3 entries (structural invariants)
● hsl(7.18, 100%, 50%) class [feature]
● hsl(0.00, 100%, 50%) public [feature]
● hsl(84.10, 100%, 50%) namespace [feature]
UNOBSERVED — 0 entries (implied truths)
OBSERVED — 9 entries (explicit in request)
◉ hsl(10.26, 100%, 15%) enum [feature]
◉ hsl(34.87, 100%, 15%) switch [feature]
◉ hsl(92.31, 100%, 15%) value [feature]
◉ hsl(133.33, 100%, 15%) string [feature]
◉ hsl(215.38, 100%, 15%) switch [feature]
◉ hsl(248.21, 100%, 15%) Switch expression [feature]
◉ hsl(249.23, 100%, 22%) With expression [feature]
◉ hsl(264.62, 100%, 22%) is expression [feature]
◉ hsl(265.64, 100%, 22%) as expression [feature]
COMPLEXITY │ 12 entries │ spread: 255° │ band: MEDIUM
Baseline response (no ZPI)
### Enum to String Mapping using Switch Expression
Here's an example of how you can use a switch expression to map an enum value to a string in C#.
```csharp
// Define an enum
public enum Color
{
Red,
Green,
Blue
}
public class Program
{
public static void Main()
{
// Use a switch expression to map an enum value to a string
Color color = Color.Green;
string colorName = color switch
{
Color.Red => "Red",
Color.Green => "Green",
Color.Blue => "Blue",
_ => "Unknown color"
};
Console.WriteLine(colorName); // Outputs: Green
}
}
```
In this example, the switch expression checks the value of the `color` variable and returns the corresponding string. If the value doesn't match any of the specified cases, it returns "Unknown color".
### Using a Dictionary for Mapping
Alternatively, you can use a dictionary to map enum values to strings. This approach can be more efficient and easier to maintain if you have a large number of enum values.
```csharp
// Define an enum
public enum Color
{
Red,
Green,
Blue
}
public class Program
{
private static readonly Dictionary<Color, string> colorMap = new()
{
{ Color.Red, "Red" },
{ Color.Green, "Green" },
{ Color.Blue, "Blue" }
};
public static void Main()
{
// Use the dictionary to map an enum value to a string
Color color = Color.Green;
string colorName = colorMap.TryGetValue(color, out string? name) ? name : "Unknown color";
Console.WriteLine(colorName); // Outputs: Green
}
}
```
In this example, the `colorMap` dictionary stores the mapping between enum values and strings. The `TryGetValue` method is used to retrieve the string value for a given enum value, and if the value is not found, it returns "Unknown color".
Enhanced response (with ZPI)
```csharp
using System;
public enum Color
{
Red,
Green,
Blue
}
public class Program
{
public static string GetColorName(Color color) => color switch
{
Color.Red => "Red",
Color.Green => "Green",
Color.Blue => "Blue",
_ => throw new ArgumentOutOfRangeException(nameof(color), color, null)
};
public static void Main()
{
Console.WriteLine(GetColorName(Color.Red)); // Outputs: Red
Console.WriteLine(GetColorName(Color.Green)); // Outputs: Green
Console.WriteLine(GetColorName(Color.Blue)); // Outputs: Blue
}
}
```
This C# code uses a switch expression to map an enum value of type `Color` to its corresponding string representation. The `GetColorName` method takes a `Color` enum value as input and returns the associated string. If the input enum value does not match any of the specified cases, it throws an `ArgumentOutOfRangeException`.
The switch expression is a concise way to express simple conditional logic, making the code more readable and efficient. The `_` wildcard pattern is used to handle any unexpected enum values, ensuring that the method is robust and handles potential errors.
Grader chain
Each grader reads the same baseline + enhanced pair and casts an independent verdict. Disagreement is the framework's own signal — not noise to be averaged away.
V1samba/Meta-Llama-3.3-70B-Instruct
BetterV4qwen2.5-coder-3b-instruct
BetterV5openrouter/qwen/qwen3-235b-a22b-2507
BetterV7qwen2.5-coder-7b-instruct
BetterV8openai/gpt-4.1
BetterV9anthropic/claude-opus-4-7
WorseV12openai/gpt-4o
BetterComments
Our grader said what it said. What do you say? Comment as a guest below.
No comments yet. Be the first to say what you make of this round.