Programming Languages Project

Hi this is what i managed to make i did not get a error code from these:

Pretty print all:


public static void PrettyPrintAll(IEnumerable<Language> langs)

{

 foreach (var printsAll in langs)

  {

    Console.WriteLine(printsAll.Prettify());

  }
}

print all:


public static void PrintAll(IEnumerable<Object> sequence)

{

  foreach (var prints in sequence)

  {

    Console.WriteLine(prints);

  }

}

The problem now is that i dont now how to print them i did not manage to.

I had a similar problem earlier when i was trying to do task nr 3, it turned out i was missing part of the syntax.

Here is what i tried first:


var msLangs = languages.Where(lang => ChiefDeveloper.Contains("Microsoft"));

Here is the code that worked:


var msLangs = languages.Where(lang => lang.ChiefDeveloper.Contains("Microsoft"));

I will take a look at our codes and see how they compare but i figured i am better off trying to learn more and then come back to do this project one more time.

All the correct namespaces are added in the project when you start.

Also one final tip, you can format your code in your posts with 4 spaces so your code becomes more readable, i learned this on stackoverflow got roasted when i did not do it correctly lol. i See that you have done it in the second post though.

When i try this i get: error CS0103: The name ‘PrettyPrintAll’ does not exist in the current context [/home/ccuser/workspace/csharp-programming-languages/ProgrammingLanguages.csproj]

Thanks for the tip. I need to learn to use the PreformattedText command in the palette to post code. Hopefully this will be clearer.

#10) PrettyPrintAll()
Your code inside the method works OK… I pasted it into my console and it printed out all of the lines from the Languages list as intended. You mentioned that you get Error CS0103 when you call the method with the “languages” argument. Maybe this is the source of the problem.

Perhaps the method is hidden or embedded inside of another function like an “if” statement or perhaps there are a couple of stray braces left over from another statement? Can you verify that both the method and the callout are contained within the set of braces in Main()?

static void Main()
{
}

Also, both the method and the method callout should be in the Program.cs file (and not in Languages.cs). Sometimes I am not sure if a particular batch of code should be entered into Program.cs or into the associated files.

#11) PrintAll()
Your PrintAll() method also functions OK when I paste it into my console. I am able to print out the data containing the NAME and the YEAR of the oldest languages from the YEAR 1990. The data is Selected using the LINQ Method syntax (2 statements) and then that file is used as the argument when calling the method. Do you also get the Error CS0103 when you call the method?

Yes i do bro, most likely i did something wrong somewhere else.
So what did you decide to do after this project?

Did you try to do the Build Web Apps with ASP.NET?

https://www.codecademy.com/learn/paths/build-web-apps-with-asp-net

It worked when moved to main, but i think this is the incorrect way to do it. The reason why the public modifier is not needed when the methods is moved to main is because when they are in main we dont access them from somewhere else so they dont need an access modifier.

Most likely there is another way to print them but i am to afraid to ask in stackoverflow the people there can be pretty harsh to beginners.

edit:

I asked in stackoverflow and got the solution (Oh my oh my i feel really stupid now lol).
With the methods in Language.cs you would use this syntax to call the method PrettyPrintAll:

var langScripts = languages

        .Where(language => language.Name.Contains("Script"));

        Language.PrettyPrintAll(langScripts);

To print out PrintAll:

var stringLanguage = languages.Select(languagePrint => $"{languagePrint.Year} {languagePrint.Name} {languagePrint.ChiefDeveloper}");

Language.PrintAll(stringLanguage );

Now you can have the methods in Language.cs with the public modifier.

I am in the process of wrapping up the “Console Game” project and attempting to decipher the code that capture key strokes so I can make my own changes. Stuck on that.

You solved the mystery! No doubt I need to go back and move those methods over into Games.cs. That also resolves the Error related to the PUBLIC modifier. That was kind of bothering me. Makes sense now I suppose.

I’m also still learning how to navigate around the Visual Studio.

Cool

Let me know if you need help, or advice.

Very good; thanks! For now I’ll start messing around with the basic Console.Readkey() and hopefully move forward from there.

Confirming that I moved the methods over to Languages.cs as you suggested and that everything prints out after calling them in Program.cs using the syntax that you entered above.

At first, it threw Error CS0246: “The namespace “IEnumerable” could not be found.” This is resolved by adding this USING statement to Languages.cs:

using System.Collections.Generic;

(It is already in Program.cs)
Just a heads-up for the benefit of anyone who may get the same error.

to use the public modifier, you have to define the method inside of program.cs but OUTSIDE of main (right after the main closing curly brace). that’s what i did and it worked for me.

you can see it here in the method section of the course:

https://www.codecademy.com/courses/learn-c-sharp/lessons/csharp-method-calls-and-input/exercises/define-a-method

to use the public modifier, you have to define the method inside of program.cs but OUTSIDE of main (right after the main closing curly brace). that’s what i did and it worked for me.

you can see it here in the method section of the course:

https://www.codecademy.com/courses/learn-c-sharp/lessons/csharp-method-calls-and-input/exercises/define-a-method

For the #11 You will also need to add the Select operator to the objects on number 3, 4 and 5 to have what they asked printed out to the console or you will just end up having: ProgrammingLanguages.Language printed.

I got my code sorted up until step 11.

My code looks like this for it:

public static void PrintAll(IEnumerable<Object> sequence) {
      foreach (Object o in sequence) {
        Console.WriteLine(o);
      }
    }

And in the main method I called it with:

PrintAll(languages);

All it’s spitting out is a bunch of text saying “ProgrammingLanguages.Language”.

I’m not sure if this is right and what they want.
The rest of my functions and loops work fine.

Is there anyone who knows what to do there? Been puzzling me for works since finishing C#.

I think you are incorrect because all the other methods that was there from before is in Language.cs furthermore i think its bad practice to define the methods in program.cs because it makes it more difficult to make changes later and if you have a lot of methods program.cs will get chaotic.

you can see what to do in my comment right above your comment :wink:

there is only one method defined in language and it’s Prettify because all languages will use it. And since they taught us to do it that way earlier AND the fact that it worked like a charm, i’m thinking that it was the right way. but to be honest, having a moderator to tell us if we are right or wrong would be the best. @mtf

Hi, if you read my comments you will find the solution to this if you have not solved it already.

public static void PrintAll(IEnumerable<Object> sequence)
        {
            foreach (var prints in sequence)
            {
                Console.WriteLine(prints);
            }
        }

And in main to call the method

Language.PrintAll(stringLanguage);

In your first task you created something like this:

var stringLanguage = languages.Select(languagePrint => $"{languagePrint.Year} {languagePrint.Name} {languagePrint.ChiefDeveloper}");

The thing is that all these methods are create for Languages.cs if example we had a different file called somethingelse.cs the methods for that file would be created inside it. Btw if you look at my comments i have solved everything and enhanced the code to make it better.

Has anyone got any intel on q8?! Struggling with this. Frustrating as it’s slightly different to no7 but I guess i’m going wrong with the syntax for the comparisons operators.

So far I have;

var newLang = languages

.Where (x => x.Year => 1995 && x.Year <= 2005)

.Select(x => x.Year.Count());

Console.WriteLine(newLang.Count());

Any help greatly appreciated!

SOLVED IT!

For those wondering in future this worked:

var newLang = languages

.Where (x => (x.Year >= 1995 && x.Year <= 2005));

Console.WriteLine(newLang.Count());

Hi

Finsihed my project anyfeedback please specially on step 10 or 11 or 12
Programming Languages using c#

Cheers
Atif