Until now, if you wanted to access the last item in a list you had to use a slightly cumbersome syntax. C# 13 introduces the “hat” operator (^) where ^1 is the last element in your collection, ^2 is the penultimate member, etc.
Like many things, this is best illustrated with an example. In the following code I create a simple Person class and initialize a list<Person> with three people (persons?)
internal class Program
{
static void Main(string[] args)
{
var tester = new Tester();
tester.Test();
}
}
public class Tester()
{
public void Test()
{
var john = new Person { Name = "John", Age = 25 };
var jane = new Person { Name = "Jane", Age = 30 };
var joe = new Person { Name = "Joe", Age = 35 };
var people = new List<Person> { john, jane, joe };
}
}
public class Person()
{
public string Name { get; set; }
public int Age { get; set; }
}
Straight forward. Now, if I want to access the last person in this list I can write
var lastPerson = people[^1];
Console.WriteLine($"Last person is {lastPerson.Name} who is {lastPerson.Age} years old.");
As you can see, this is concise and easy to understand. You read it as “lastPerson is equal to one back from the end of people.” Let’s run it:
Last person is Joe who is 35 years old.
That is all there is to it. Easy to use and somewhat helpful in simplifying your code.






































Greate pieces. Keep writing such kind of info on your page. Im really impressed by your blog.
mexican pharmacies: mexico online pharmacy – farmacias mexicanas
After going over a few of the blog posts on your website, I honestly like your way of writing a blog. I added it to my bookmark webpage list and will be checking back soon. Please visit my web site too and let me know how you feel.
This article serves as a fantastic starting point for anyone looking to get acquainted with the material, and your clear formatting ensures that the main takeaways are immediately visible to the audience.
kinghills
Currently it seems like BlogEngine is the preferred blogging platform out there right now. (from what I’ve read) Is that what you are using on your blog?
Aw, this was an extremely nice post. Spending some time and actual effort to generate a great article… but what can I say… I put things off a whole lot and never manage to get anything done.
Greate article. Keep writing such kind of info on your site. Im really impressed by your site.
Hiya, I am really glad I have found this info. Nowadays bloggers publish just about gossips and web and this is actually annoying. A good site with exciting content, that’s what I need. Thanks for keeping this web-site, I will be visiting it. Do you do newsletters? Can’t find it.
I was very pleased to find this web-site.I wanted to thanks for your time for this wonderful read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you blog post.
Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.
Its excellent as your other content : D, regards for posting. “Love is like an hourglass, with the heart filling up as the brain empties.” by Jules Renard.
Rattling nice style and fantastic content material, practically nothing else we require :D.
Everything is very open and very clear explanation of issues. was truly information. Your website is very useful. Thanks for sharing.
Right now it looks like Movable Type is the best blogging platform available right now. (from what I’ve read) Is that what you are using on your blog?
Aw, this was an extremely good post. Taking the time and actual effort to produce a superb article… but what can I say… I procrastinate a whole lot and never manage to get anything done.
Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this. Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.
Wow that was unusual. I just wrote an extremely long comment but after I clicked submit my comment didn’t appear. Grrrr… well I’m not writing all that over again. Anyway, just wanted to say great blog!
Usually I don’t read post on blogs, but I would like to say that this write-up very forced me to try and do so! Your writing style has been amazed me. Thanks, quite nice article.