Wrox Programmer Forums
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 16th, 2007, 04:08 PM
Authorized User
Join Date: Dec 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Get the first item of a List

I have a List<Type> that I know will always contain only one item and I want to get that item.

I can't find a simple method that will let me do that in one line! DO I really have to get the Enumerator or do a foreach?


Old February 16th, 2007, 06:04 PM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Would myList[0] work?

And if you know it will only contain one item, wouldn't it be better to declare it as T instead of List<T>??

Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.

Similar Threads
Thread Thread Starter Forum Replies Last Post
List name of item from folder 'My Picture' mona_upm84 Excel VBA 2 September 4th, 2008 05:54 PM
Invisible List Item? The Duke ASP.NET 3.5 Professionals 0 September 1st, 2008 12:14 PM
Adding List Item Programmatically rit01 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 2 February 12th, 2006 04:51 PM
How to populate list item shankhan Classic ASP Databases 5 March 23rd, 2005 04:03 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.