C# Programming Languages Project

[Learn C# | Codecademy]
(https://www.codecademy.com/courses/learn-c-sharp/projects/csharp-programming-languages)

Hi team

Please can someone post a solution to this project? There is no solution provided with the project and I’m unable to check where I’m going wrong. Getting loads of errors from Step 1 alone (which is unusual).

Here’s what I’ve got for Step 1:

foreach (Language language in languages)

    {

      Console.WriteLine(language.Prettify());

    }

Thank you
Tanya

You need to make sure you keep the code that is already in the main function of Program.cs:

List<Language> languages = File.ReadAllLines("./languages.tsv")
        .Skip(1)
        .Select(line => Language.FromTsv(line))
        .ToList();

Thank you for getting back to me so quickly - I have kept it in there (I just didn’t paste it here as I was only pasting what I had added so far). Apologies for not making that clear.

It works when I put it in. You’re doing in Program.cs, right? Does your output look like this

It doesn’t, just a bunch of errors but it also keeps crashing… I think I’ll reboot everything and try again. Thanks for your help!
If you/anyone has finished the project, it would be good to compare against solution code at the end.

1 Like

Instead of “foreach (Language language in languages)”

try

“foreach (var language in languages)”

The reason is that each Language contains an int variable and 3 strings, so each component in “language” is not itself a Language.

Hope this works!

I’m stuck on the last task:
" Find the oldest language in the list using the Min() method]."
I’ve managed to get the minimum year, but I can’t manage to get the language that corresponds to that year.
Unfortunately the solution video also doesn’t show that.

The last thing I tried was:

var langYearMin = languages.Min(x => x.Year);

var langMin = from language in languages
where language.Year.Contains(langYearMin)
select language;

But I’m still getting error: "Program.cs(82,7): error CS1929: ‘int’ does not contain a definition for ‘Contains’ and the best extension method overload "
I’ve also tried with:

var langMin = from language in languages
where language.Year == langYearMin
select language;

But then I get this: “System.Linq.Enumerable+WhereListIterator`1[ProgrammingLanguages.Language]”

And I think I’ve tried everything I could think of in the last few hours.
Please help.

Ok, got it. It’s always like that - I need to write it down on a forum, then I find the solution myself… LOL
The solution here, in case there is someone else like me… :slight_smile:

 var langMin = from language in languages
                where language.Year == langYearMin
                select language.Name;  // first mistake was here - i didn't return a list with the names

foreach (var xx in langMin)  // second silly mistake was here - i didn't create a foreach-loop to print out each member
{ Console.WriteLine(xx); }