Click here to Skip to main content
15,917,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
want to get id and a value stored against it.
value is in float.
i m trying to sort the value and then show it according to the corresponding id.

What I have tried:

C#
public List<data> GetStuCosineSimilarity()
        {
            Dictionary data = new Dictionary<int,double>();
            List<data> stuId = new List<data>();
            

            data = (from s in DB.Students
                     select new
                     {
                         id = s.StudentId,
                         cosine = s.cosineSimilarity
                     }).ToList();
            return stuId;
        }
Posted
Updated 30-Apr-16 0:07am
v2
Comments
Karthik_Mahalingam 30-Apr-16 5:51am    
What issue you are facing?

1 solution

Try this,

Create a class with the properties as
C#
public class Student
   {
       public int Id { get; set; }
       public float Cosine { get; set; }
   }


and your method should be edited as

C#
public List<student> GetStuCosineSimilarity()
        { 
            List<student> lst = new List<student>();

            lst = (from s in DB.Students
                   select new Student()
                   {
                       Id = s.StudentId,
                       Cosine = s.cosineSimilarity
                   }).ToList();

            lst = lst.OrderBy(k => k.Cosine).ToList(); // Sorting the float value
            return lst;
        }
 
Share this answer
 
v3
Comments
Danyal Awan 30-Apr-16 6:19am    
i have change
public double Cosine { get; set; }

now its giving error on s.cosineSimilarity
(cannot implicitly convert type 'double?' to 'double'. An explicit conversion exists (Are you missing a cast?) )
Karthik_Mahalingam 30-Apr-16 6:22am    
Use

public double? Cosine { get; set; }
Danyal Awan 30-Apr-16 6:40am    
thanks it worked... :)
Karthik_Mahalingam 30-Apr-16 11:00am    
Welcome :)
Danyal Awan 30-Apr-16 9:02am    
now how to get only int part from the list in array?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900