CANNOT CONVERT INT TO STRING

Jeet Verma

Total Post:110

Points:776
Posted by  Jeet Verma
C# 
C#
 1481  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. Sumit Kesarwani

    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

                            };

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!