Click here to Skip to main content
15,886,578 members
Home / Discussions / C#
   

C#

 
AnswerRe: Plotting serial port data using zedgraph (data vs time) Pin
Gerry Schmitz8-Mar-17 6:39
mveGerry Schmitz8-Mar-17 6:39 
GeneralRe: Plotting serial port data using zedgraph (data vs time) Pin
Ram _Varman9-Mar-17 2:59
Ram _Varman9-Mar-17 2:59 
GeneralRe: Plotting serial port data using zedgraph (data vs time) Pin
Gerry Schmitz9-Mar-17 6:08
mveGerry Schmitz9-Mar-17 6:08 
Questionreferencing a dll available in a different folder from a Windows Service without copying the dll Pin
govindarajan k8-Mar-17 0:24
govindarajan k8-Mar-17 0:24 
AnswerRe: referencing a dll available in a different folder from a Windows Service without copying the dll Pin
Pete O'Hanlon8-Mar-17 0:40
mvePete O'Hanlon8-Mar-17 0:40 
AnswerRe: referencing a dll available in a different folder from a Windows Service without copying the dll Pin
Alan N8-Mar-17 3:58
Alan N8-Mar-17 3:58 
GeneralRe: referencing a dll available in a different folder from a Windows Service without copying the dll Pin
govindarajan k9-Mar-17 0:27
govindarajan k9-Mar-17 0:27 
QuestionLINQ error string matching? Pin
Member 28240516-Mar-17 4:41
Member 28240516-Mar-17 4:41 
I found an Unexplainable behaviour of LINQ in a tutorial code example from this site:

How to: Populate Object Collections from Multiple Sources (LINQ) (C#)
https://docs.microsoft.com/en-us/dotnet/articles/csharp/programming-guide/concepts/linq/how-to-populate-object-collections-from-multiple-sources-linq


How to: Join Content from   
        // Dissimilar Files (LINQ).  


starting from 2 Files:
names.csv
-----------------------------------
Omelchenko,Svetlana,111  
O'Donnell,Claire,112  
Mortensen,Sven,113  
Garcia,Cesar,114  
Garcia,Debra,115  
Fakhouri,Fadi,116  
Feng,Hanying,117  
Garcia,Hugo,118  
Tucker,Lance,119  
Adams,Terry,120  
Zabokritski,Eugene,121  
Tucker,Michael,122  


scores.csv
-----------------------------------
111, 97, 92, 81, 60  
112, 75, 84, 91, 39  
113, 88, 94, 65, 91  
114, 97, 89, 85, 82  
115, 35, 72, 91, 70  
116, 99, 86, 90, 94  
117, 93, 92, 80, 87  
118, 92, 90, 83, 78  
119, 68, 79, 88, 92  
120, 99, 82, 81, 79  
121, 96, 85, 91, 60  
122, 94, 92, 91, 91   


Code:

class Student  
{  
    public string FirstName { get; set; }  
    public string LastName { get; set; }  
    public int ID { get; set; }  
    public List<int> ExamScores { get; set; }  
}


//

public static void Main()  
{
 
 	 
 	 string filepathname = @"C:\LINQPad\";  
	 string[] names = System.IO.File.ReadAllLines(filepathname + "names.csv");  
 
	 string[] scores = System.IO.File.ReadAllLines(filepathname + "scores.csv");       

        IEnumerable<Student> queryNamesScores =  
            from nameLine in names  
            let splitName = nameLine.Split(',')  
            from scoreLine in scores  
            let splitScoreLine = scoreLine.Split(',')  
            where splitName[2] == splitScoreLine[0]  // no match??			
            select new Student()  
            {  
                FirstName = splitName[0],  
                LastName = splitName[1],  
                ID = Convert.ToInt32(splitName[2]),  
                ExamScores = (from scoreAsText in splitScoreLine.Skip(1)  
                              select Convert.ToInt32(scoreAsText)).  
                              ToList()  
            };         
  
        List<Student> students = queryNamesScores.ToList();  

        // Display each student's name and exam score average.  
        foreach (var student in students)  
        {  
            Console.WriteLine("The average score of {0} {1} is {2}.",  
                student.FirstName, student.LastName,  
                student.ExamScores.Average());  
        } 
 
 }


 Expected Output:   
    The average score of Omelchenko Svetlana is 82.5.  
    The average score of O'Donnell Claire is 72.25.  
    The average score of Mortensen Sven is 84.5.  
    The average score of Garcia Cesar is 88.25.  
    The average score of Garcia Debra is 67.  
    The average score of Fakhouri Fadi is 92.25.  
    The average score of Feng Hanying is 88.  
    The average score of Garcia Hugo is 85.75.  
    The average score of Tucker Lance is 81.75.  
    The average score of Adams Terry is 85.25.  
    The average score of Zabokritski Eugene is 83.  
    The average score of Tucker Michael is 92.  
*/


* Real Output:  
    … nothing ….
*/


Why does LINQ not match correctly 
At this point of code:

where splitName[2] == splitScoreLine[0]  // no match??		

And therefore no output will be generated

Thanks for advice

Alberto

ALBAB

AnswerRe: LINQ error string matching? Pin
Richard Deeming6-Mar-17 5:36
mveRichard Deeming6-Mar-17 5:36 
GeneralRe: LINQ error string matching? Pin
Member 28240516-Mar-17 20:28
Member 28240516-Mar-17 20:28 
QuestionWorking with .resx Files / C#, WinForms [Closed] Pin
HobbyProggy5-Mar-17 21:44
professionalHobbyProggy5-Mar-17 21:44 
AnswerRe: Working with .resx Files / C#, WinForms Pin
Gerry Schmitz6-Mar-17 9:42
mveGerry Schmitz6-Mar-17 9:42 
GeneralRe: Working with .resx Files / C#, WinForms Pin
HobbyProggy6-Mar-17 19:27
professionalHobbyProggy6-Mar-17 19:27 
GeneralRe: Working with .resx Files / C#, WinForms Pin
Gerry Schmitz6-Mar-17 20:08
mveGerry Schmitz6-Mar-17 20:08 
GeneralRe: Working with .resx Files / C#, WinForms Pin
HobbyProggy6-Mar-17 20:24
professionalHobbyProggy6-Mar-17 20:24 
GeneralRe: Working with .resx Files / C#, WinForms Pin
Gerry Schmitz6-Mar-17 20:41
mveGerry Schmitz6-Mar-17 20:41 
GeneralRe: Working with .resx Files / C#, WinForms Pin
HobbyProggy6-Mar-17 21:45
professionalHobbyProggy6-Mar-17 21:45 
GeneralRe: Working with .resx Files / C#, WinForms Pin
Gerry Schmitz6-Mar-17 22:02
mveGerry Schmitz6-Mar-17 22:02 
GeneralRe: Working with .resx Files / C#, WinForms Pin
HobbyProggy6-Mar-17 22:13
professionalHobbyProggy6-Mar-17 22:13 
GeneralRe: Working with .resx Files / C#, WinForms Pin
Gerry Schmitz6-Mar-17 22:30
mveGerry Schmitz6-Mar-17 22:30 
Questionwebrequest sent twice Pin
Forest44734-Mar-17 22:32
Forest44734-Mar-17 22:32 
AnswerRe: webrequest sent twice Pin
Michael_Davies4-Mar-17 22:59
Michael_Davies4-Mar-17 22:59 
GeneralRe: webrequest sent twice Pin
Forest44734-Mar-17 23:15
Forest44734-Mar-17 23:15 
GeneralRe: webrequest sent twice Pin
Michael_Davies4-Mar-17 23:43
Michael_Davies4-Mar-17 23:43 
AnswerRe: webrequest sent twice Pin
Richard Deeming5-Mar-17 23:52
mveRichard Deeming5-Mar-17 23:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.