p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 (http://p2p.wrox.com/forumdisplay.php?f=389)
-   -   Chap 16 pg 570 System.Collections.Generic has some invalid arguments (http://p2p.wrox.com/showthread.php?t=75564)

tomche August 5th, 2009 08:19 AM

Chap 16 pg 570 System.Collections.Generic has some invalid arguments
 
Hello,

I get the following error message after typing in the code for the Try It Out on pg 570.

List<int> ProfileCommon.FavouriteGenres


Error:
The best overloaded method match for 'System.Collections.Generic.List<int> .Add(int) has some invalid arguments


This occurs under the following line

Profile.FavouriteGenres.Add(Convert.ToInt32{myItem .Value));

My MyProfile.aspx.cs file looks like this

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class MyProfile : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
txtFirstName.Text = Profile.FirstName;
txtLastName.Text = Profile.LastName;
txtDateOfBirth.Text = Profile.DateOfBirth.ToShortDateString();
txtBio.Text = Profile.Bio;
}

}
protected void btnSave_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
Profile.FirstName = txtFirstName.Text;
Profile.LastName = txtLastName.Text;
Profile.DateOfBirth = DateTime.Parse(txtDateOfBirth.Text);
Profile.Bio = txtBio.Text;
Profile.FavouriteGenres.Clear();
foreach (ListItem myItem in CheckBoxList1.Items)
{
if (myItem.Selected)
{
Profile.FavouriteGenres.Add(Convert.ToInt32{myItem.Value));
}
}
}
}
}
protected void CheckBoxList1_DataBound(object sender, EventArgs e)
{
foreach (ListItem myItem in CheckBoxList1.Items)
{
int currentValue = Convert.ToInt32(myItem.Value);
if (Profile.FavouriteGenres.Contains(currentValue))
{
myItem.Selected = true;
}
}
}
}

Are there any words of wisdom out there?

Cheers

Thomas

Imar August 5th, 2009 08:58 AM

Hi there,

What version / language of the book are you using? In my version there's no code on page 570. Can you provide more information?

The code you posted (List<int> ProfileCommon.FavouriteGenres) doesn't look good but I don't know what it should be exactly as I don't know what exercise you're in.

Imar

tomche August 6th, 2009 07:42 AM

Hi Imar,
I am programming in c# and the code is actually on pg 572 but begins on page 570.

Regards

Thomas

Imar August 6th, 2009 08:00 AM

It could be me, but I don't see anything that looks like

List<int> ProfileCommon.FavouriteGenres

on that page. There's no List<int> there....

Imar

tomche August 6th, 2009 08:10 AM

Hello Imar,

I am glad you said that and not me because I couldn't see it in the code I posted above.

Do you know what that error message generally refers to?

Cheers

Thomas

Imar August 6th, 2009 08:41 AM

Ah, now I understand. The error message you posted didn't look like an error message so I thought it was code you typed in....

That brought me to this:

Profile.FavouriteGenres.Add(Convert.ToInt32{myItem .Value));


See that { that should be a ( ?

Imar

tomche August 6th, 2009 09:29 AM

Thank you Imar.

I shouldn't really come to you with questions that have answers as simple as that.

That wrox!

Thome

Imar August 6th, 2009 10:08 AM

You're welcome....

The compiler isn't giving a too helpful error here, so I can imagine the confusion...

Imar


All times are GMT -4. The time now is 07:03 PM.

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