← Back
Nick Chapsas November 10, 2026 11m

The Weirdest Feature Microsoft Added in C# 15

Read full transcript 9 segments
  1. Hello everybody, I'm Nick and in this video I want to talk about what seems to be the goofiest of features that is being added in C 15. And it's goofy because it feels like it should have been there from the first version or not at all. So let me explain. Let me show what I have here. I have a simple console application and I have two hello worlds. Hello world and hello world again. Now many of you might not know this but car has a very interesting combination of features. If I just was to run this, obviously you're going to see hello world and then hello world again. Basic stuff. But I could go here between the two console right lines and say um skip. And then if I put a colon over here, not like this, like this. Go away rider. Stop being annoying. Then in case you don't know what this is, this is called a label. I know many people still don't know that this feature exists. But if you give any name and then you put the colon and this yeah this can be anything. Um then you can have a named label in your car code. And if you go somewhere and you type go to and then the name of the label. If you run this code obviously you see it blacked out. it's going to skip because it's going to see that go to statement and go to another area. This is not new.

  2. This existed for a very long time and people are mostly not using it rightfully so because go to sort of messes up the control flow and it's not really obvious what's going to happen. Yes, here when you have four lines of code you can tell what's going on. But if this was a bit more elaborate, for example, if it was loops and nested code and so on, then it kind of feels wrong. It kind of feels like you're using exceptions for control flow to to achieve something similar, which is not ideal, but it exists. And have I used it? Absolutely. Because sometimes when you're just doing throwaway console like scripting C stuff, it makes sense to use if your brain, which in my case it doesn't do that. that if your brain is just too overoccupied with the script itself and sometimes I have to spend more time to figure out what's going on. That's a problem I have and most people don't have it. But I have used this.

  3. However, here's what's coming in C 15. And it's going to be super obvious why I say this should have been in the language from the very first version. So what do I have here? I have um uh this array over here where I have a bunch of order of item array elements. So let's say that this is one mouse, two keyboards and three monitors in an order. That's what this is supposed to represent here. Obviously, you cannot have zero monitors or zero keyboards. So this is an invalid order. This is a valid one because you can have two mice and one keyboard and you can't have minus one uh mice. Now here's the goal. The goal is to stop checking all orders at the first invalid quantity. So traditionally before C 15 what you would do is you would say that okay let me iterate over that and then you would iterate over the length of the array then get each item check the order and then with a for each loop or a nested loop in general you're going to check for a negative quantity and then you you would break so you would break out of the inner for each loop and then you would continue on the outer. Now that's the problem because break in this case only exists within the for each loop. So if you break in here, this wouldn't break the processing of the outer loop which is what we would want to do. So how would you fix that before C 15?

  4. Well, you would carry some state. So you would say something like var boolean like found invalid quantity and you would set that to false. And then the moment you found some invalid quantity then you would set that to true. Then you would break and then you would say on the outer array or on the outer iteration hey did you find an invalid quantity? If you did then break out of the outer for loop as well. And you can understand the more nesting you have which you shouldn't but it happens. You know nesting is naturally occurring. Uh you'd have to carry this state. It's not the most elegant piece of code you can have. It's a bit hard to read as well, but that's how we would do it before C 15. Now, in C 15, we get the ability to do the following. We can now add a label to a construct like a loop or a switch statement. You can break out of a switch statement, but you can't really continue. Continue is exclusive for loops. We're going to see how that works in a second. But you can now say that this is my outer loop. So you can label the outer loop and then here you can say break to the outer loop. So it is a bit like a go to statement but now it's baked into the break and the continue statements. So that exact code as before does not need to carry that thing

  5. anymore. Now you can just go straight away and say I want to break here. Is this super readable? I think it is. The problem is it's completely new for a version that has been around for 20some years. So its drawback is not that it's not a good feature. Its drawback is that it comes so late that I don't think people will use it as much. Now agents might still want to use it. I know I talk about agents a lot, but agents might still want to use this feature to write better code and agent code matters because agent code should be code you would have written anyway. That's how I personally like to treat agentic tools like clo code and codex. Obviously, your agents will not know this straight away. So, if you want your agents to be trained in every C# 15 feature, I wrote a skill you can add to your agent and then it will know how to use it. I'm going to link in the description down below. You can just download it and add it into close codeex or anything you use copilot cursor. It works everywhere and we'll know how to use this.

  6. Is this amazing? It's fine. You know, it's it it's so weird to me that this is being added because this is such an obvious quality of life change. Like it makes sense for this thing to be there. And by the way, this would also work if you if you write it like this. It will still understand that this is associated with this specific loop. But I like this syntax where you you sort of label the construct directly because now I know that this outer label is about this loop. So that's how I would write it. Now you can write it any way you want. It makes a lot of sense to be there. I just think it's just so late that when people encounter this, they're going to be like, "What the hell is that? Am I gotoing here?" Break at least that it's not a go-to. Obviously, go to has a stigma. Um, because it's considered an antiattern in everything but C from what I understand, but I don't write C, so I don't know. So, glad this exists. And this doesn't stop there. It actually works with continue as well. So, here we have another problem. We have the goal where we want to go. we're going to skip an entire invalid order but keep checking subsequent orders. So we have the continue thing. And the problem with this nesting array without that feature is that okay if you go and iterate over the outer array and then you go inside and you find um an invalid order and you

  7. continue. This only continues on the inner loop again. So we have this nesting problem. I would really want to know why Microsoft thought this is a good feature to add. And I'm assuming they either have tons of like code generators or like source generators that might need to use this feature or agents to lead to simpler code. It it must be one of the two. I I I just don't know if this is really for humans. Maybe it is. Maybe maybe I'm I'm speculating here, but I it's such a bizarre feature to me. Leave a comment down below and let me know what you think about this and why do you think Microsoft added this? so late, 15 versions later is just insane to me. I'm glad we're getting it, but it does feel like we're adding all of the features now to to the language. And for me, a language is not defined exclusively by the features it has, but it's also defined by the features it chooses to not have. And you see that with languages like Rust, Go, etc., are aware they they could add more things, but they're very careful because the more features a language has, the more different flavors of that language's code you're going to see in the wild.

  8. It's going to be hard to work with. Anyway, in this case, we now have this and you could also have this code now solve this problem where again you would have to carry state saying valid, false, you had to break and then you'd have to continue on the outer loop from the inner loop. Well, this is hard to read. I I I understand this is really really hard to read. So I understand why with continue now you can label the outer loop again and you can continue not just break on the outer loop. This is awesome. This I like. It reads nice once you understand what this feature is doing. But again it's it's that thing where this should have been a core language. It feels like one of those fundamental language features and we're just getting it now. I digress. I've been going in cycles. That's what we're getting. It is cool. I just I just don't know how I feel about it. I really want to know how you feel about it in the comments just down below. Did we need this? And if we add this, is there anything else we can do with this goto like syntax in C? Just leave a comment down below and let me know. Now before I leave you, I do want to let you know that at dome trainin my courses platform, we did just launch our Black Friday sale. It's the biggest sale we do every year. So if you're thinking of grabbing a course on either any C subject because we have tons MCPS, cloud

  9. code, cursor, GitHub copilot, we cover everything that you really should at least know in the agentic era. As much as I don't like this term, these tools are extremely powerful. So if you want to grab any of those, you can. But the exciting part for me is that we just launched Android and iOS apps that bring not only all the video courses we have with offline downloads, etc., but also all of our hands-on stuff. So if you want to type code on your phone to learn how to code or if you want to take any of the certificate courses we have which most of them are free as well. Uh or even if you want to run Linux like an actual Linux distro on your phone to learn Linux which is what I've been doing ever since Omari came out then you can download the apps try them out. They're free. Just just give it a go. I'm just very happy to have an app on the app store and I'm so proud of the dome train team. But now I want to know from you, what do you think about this feature and what else should Microsoft add in the language? Leave a comment down below and let me know. Well, that's all I had for you for this video. Thank you very much for watching and as always, keep coding.

Summary

This video discusses a new feature coming in C# 15 that allows developers to add labels to loops and switch statements to break out of nested structures more easily. Key subjects include traditional go-to statements, nested loop control flow, state management, and the use of AI coding agents to write clean code. The practical takeaway is that while this long-overdue quality-of-life update greatly improves readability by eliminating manual state flags, developers and their AI agents will need training to effectively adopt the new syntax.

View original episode ↗