cannot convert int to string

Total Post:110

Points:776
C# 
C#
 1788  View(s)
Ratings:
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?

  1. Post:378

    Points:2694
    Re: cannot convert int to string

    Hi Jeet,


    try this:

    var query = from s in student                        select new ListItem                        {
                                ID = Convert.ToString(s.studentId),                            Name = s.studentName
                            };

      Modified On Apr-05-2018 05:50:24 AM

Answer