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.

Howdy I am so glad I found your site, I really found you by mistake, while I was looking on Google for something else, Anyways I am here now and would just like to say thank you for a tremendous post and a all round enjoyable blog (I also love the theme/design), I don’t have time to read through it all at the minute but I have bookmarked it and also added in your RSS feeds, so when I have time I will be back to read more, Please do keep up the excellent work.
Great work! This is the kind of information that are supposed to be shared across the internet. Disgrace on the search engines for not positioning this publish higher! Come on over and visit my website . Thanks =)
I am always browsing online for articles that can help me. Thx!
I was just seeking this info for some time. After six hours of continuous Googleing, at last I got it in your website. I wonder what’s the lack of Google strategy that don’t rank this type of informative websites in top of the list. Normally the top sites are full of garbage.
I loved as much as you’ll receive carried out right here. The sketch is attractive, your authored subject matter stylish. nonetheless, you command get bought an nervousness over that you wish be delivering the following. unwell unquestionably come further formerly again since exactly the same nearly a lot often inside case you shield this hike.
Just wanna remark on few general things, The website layout is perfect, the subject matter is real superb. “Earn but don’t burn.” by B. J. Gupta.
I’m really enjoying the theme/design of your web site. Do you ever run into any browser compatibility problems? A small number of my blog audience have complained about my website not operating correctly in Explorer but looks great in Firefox. Do you have any tips to help fix this problem?
Great write-up, I am normal visitor of one’s blog, maintain up the excellent operate, and It is going to be a regular visitor for a long time.
hi!,I like your writing very so much! percentage we keep up a correspondence extra about your post on AOL? I need an expert in this house to resolve my problem. Maybe that is you! Looking ahead to look you.
Lovely just what I was looking for.Thanks to the author for taking his clock time on this one.
Hi there! This post couldn’t be written any better! Reading through this post reminds me of my previous room mate! He always kept talking about this. I will forward this article to him. Pretty sure he will have a good read. Thank you for sharing!
Yeah bookmaking this wasn’t a risky determination great post! .
I think other web-site proprietors should take this web site as an model, very clean and great user genial style and design, as well as the content. You are an expert in this topic!
Very interesting topic, appreciate it for putting up. “Nothing is more wretched than the mind of a man conscious of guilt.” by Titus Maccius Plautus.
Outstanding post, I believe website owners should larn a lot from this web blog its real user genial.
Lovely site! I am loving it!! Will come back again. I am bookmarking your feeds also
Hello there! I could have sworn I’ve been to this website before but after browsing through some of the post I realized it’s new to me. Anyhow, I’m definitely glad I found it and I’ll be bookmarking and checking back often!
Some times its a pain in the ass to read what website owners wrote but this site is very user friendly! .
Your place is valueble for me. Thanks!…
I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post…
You actually make it appear really easy together with your presentation however I to find this topic to be really something that I think I’d never understand. It sort of feels too complicated and extremely huge for me. I am taking a look forward to your next submit, I will attempt to get the hold of it!
The Pink Salt Trick is a minimalist but effective morning routine: Just drink a glass of lukewarm water mixed with a pinch of Himalayan pink salt as soon as you wake up.
I?¦ll immediately seize your rss feed as I can’t in finding your email subscription link or newsletter service. Do you’ve any? Kindly allow me recognize in order that I may just subscribe. Thanks.
The Pink Salt Trick is a minimalist but effective morning routine: Just drink a glass of lukewarm water mixed with a pinch of Himalayan pink salt as soon as you wake up.
The Pink Salt Trick is a minimalist but effective morning routine: Just drink a glass of lukewarm water mixed with a pinch of Himalayan pink salt as soon as you wake up.
The Pink Salt Trick is a minimalist but effective morning routine: Just drink a glass of lukewarm water mixed with a pinch of Himalayan pink salt as soon as you wake up.
Hi, Neat post. There is a problem together with your website in web explorer, may check this?K IE still is the market chief and a large component to folks will leave out your great writing because of this problem.
The Pink Salt Trick is a minimalist but effective morning routine: Just drink a glass of lukewarm water mixed with a pinch of Himalayan pink salt as soon as you wake up.
My developer is trying to convince me to move to .net from PHP. I have always disliked the idea because of the costs. But he’s tryiong none the less. I’ve been using WordPress on a variety of websites for about a year and am anxious about switching to another platform. I have heard excellent things about blogengine.net. Is there a way I can transfer all my wordpress posts into it? Any help would be greatly appreciated!
Hey! Someone in my Myspace group shared this site with us so I came to give it a look. I’m definitely loving the information. I’m book-marking and will be tweeting this to my followers! Exceptional blog and brilliant design.
Good day! Do you know if they make any plugins to protect against hackers?
I’m kinda paranoid about losing everything I’ve worked hard on.
Any tips?
Also visit my webpage :: ereforce reviews
WONDERFUL Post.thanks for share..extra wait .. …
272769 668868The certain New york Diet can be an highly affordable and versatile eating far better tool built for time expecting to loose fat along with naturally maintain a healthful everyday life. la weight loss 589733
Lovely site! I am loving it!! Will come back again. I am taking your feeds also
I have been exploring for a little bit for any high-quality articles or weblog posts in this sort of area . Exploring in Yahoo I finally stumbled upon this site. Studying this info So i am happy to exhibit that I have a very excellent uncanny feeling I discovered just what I needed. I so much for sure will make sure to do not forget this site and provides it a look regularly.
Well I sincerely liked reading it. This post procured by you is very helpful for good planning.
Excellent post. I was checking continuously this blog and I’m inspired! Very helpful information specially the last part 🙂 I care for such information a lot. I used to be looking for this particular information for a long time. Thanks and best of luck.
I believe you have observed some very interesting points, appreciate it for the post.
I?¦m not certain where you’re getting your information, however great topic. I needs to spend some time studying much more or figuring out more. Thank you for magnificent info I was in search of this info for my mission.
Glad to be one of the visitants on this awesome site : D.
Very interesting topic, thanks for posting.
Does your blog have a contact page? I’m having a tough time locating it but, I’d like to shoot you an email. I’ve got some creative ideas for your blog you might be interested in hearing. Either way, great blog and I look forward to seeing it expand over time.
Thanks a bunch for sharing this with all folks you actually know what you’re speaking about! Bookmarked. Please also consult with my web site =). We may have a hyperlink trade agreement among us!
Some genuinely wondrous work on behalf of the owner of this internet site, perfectly great subject material.
Some genuinely nice stuff on this internet site, I like it.
Hiya, I am really glad I have found this information. Nowadays bloggers publish just about gossips and net and this is really irritating. A good site with exciting content, this is what I need. Thank you for keeping this website, I’ll be visiting it. Do you do newsletters? Can not find it.
I have recently started a site, the information you offer on this website has helped me greatly. Thanks for all of your time & work. “Men must be taught as if you taught them not, And things unknown proposed as things forgot.” by Alexander Pope.
Thanks for sharing excellent informations. Your web-site is very cool. I am impressed by the details that you’ve on this blog. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for more articles. You, my friend, ROCK! I found simply the information I already searched all over the place and just could not come across. What a great website.
Hi, Neat post. There’s an issue along with your web site in internet explorer, could check this?K IE still is the market chief and a large section of folks will leave out your fantastic writing because of this problem.
You are my inspiration , I possess few blogs and rarely run out from to post : (.