Home > DeveloperSection > Forums > cannot convert int to string
Jeet Verma
Jeet Verma

Total Post:110

Points:776
Posted on    September-05-2014 12:25 AM

 C# C# 
Ratings:


 1 Reply(s)
 1152  View(s)
Rate this:

var query = from s in student

            select new ListItem

            {

                ID = s.studentId,

                Name = s.studentName

            };

When I tried to execute the code I got the error

Cannot implicitly convert type 'int' (studentId) to 'string' (ID).

Is there anyway I can achieve this?



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    September-05-2014 1:06 AM

Hi Jeet,

try this:

var query = from s in student

                        select new ListItem

                        {

                            ID = Convert.ToString(s.studentId),

                            Name = s.studentName

                        };


Don't want to miss updates? Please click the below button!

Follow MindStick