How to check List's number has value?

I have generic list in some class, myCompany,


public List bookList = new List();

and this booklist will have some elements in it, book’s data.

and I want to show these book’s element’s contents. Lets say 3 books in one page,

but there maybe be 10 books in list, then last page will show only 1 book, other pages show 3 books each.

So I wrote like,

if(myCompany.bookList[pageNum*3-3].Name != ""){
GUILayout.Label(myCompany.bookList[pageNum*3-3].Name); 
.....
....
}

but if bookList has 10 books in it, it is not multiple of 3, so if pageNum*3-3 is exceed of number, error occur(Argument is out of range)

then how can I check specific bookList[some] has value or null?

if(myCompany.bookList[pageNum*3-3] != null){

this also produce same error.

Thanks.

just clamp the index value to list length

Check the count of items in the list:

   if(myCompany.bookList.Count > pageNum*3-3  myCompany.bookList[pageNum*3-3].Name != ""){
    GUILayout.Label(myCompany.bookList[pageNum*3-3].Name);
    .....
    ....
    }

Yes you r right, thx.
first I added like

if(pageNum*3-1 <= pub.bookList.Count){

but this will exceed Count because list index start from 0 and count start from 1.

so

if(pageNum*3-1 < pub.bookList.Count){

this works.