C#
C#

help

Root Question Message

Faraj
Faraj8/27/2022
Hello guys, I would like to print out the property names and the values but can't find the right

https://paste.mod.gg/rmeikgewgcfo/1
TheRanger
TheRanger8/27/2022
if ur on a Console Project just use Console.WriteLine to print the property names and their values
TheRanger
TheRanger8/27/2022
Console.WriteLine("Title: " + Title);
Faraj
Faraj8/27/2022
for example, I want to output like this: Title: Spicy-Sweet Glazed Salmon Type: Lunch Number: 2 Difficulty: Intermediate Ingredients: 2
Now it's only outputting the values
Faraj
Faraj8/27/2022
Unfortunately, I couldn't accomplish this!
TheRanger
TheRanger8/27/2022
on the same line?
TheRanger
TheRanger8/27/2022
Console.WriteLine("Title: " + Title);
Console.WriteLine("Type: " + Type);
Console.WriteLine("Number: " + Number);
Console.WriteLine("Difficulty: " + Difficulty);
Console.WriteLine("Ingredients: " + Ingredients);
Faraj
Faraj8/27/2022
Ok
Faraj
Faraj8/27/2022
Great! I'll give it a try.
Faraj
Faraj8/27/2022
Faraj
Faraj8/27/2022
Unfortunately! I got errors.
TheRanger
TheRanger8/27/2022
you need a reference of your recipe instance in order to access its members
TheRanger
TheRanger8/27/2022
eg
Console.WriteLine("Title: " + recipe1.Title);
Faraj
Faraj8/27/2022
Ok
TheRanger
TheRanger8/27/2022
my example was just if you use that code inside Recipe's method
Faraj
Faraj8/27/2022
You're awesome bro, it worked just I expected 😃
Faraj
Faraj8/27/2022
Oh my god! I spent days trying to figure out this and you just solved it in minutes.
TheRanger
TheRanger8/27/2022
you're just missing the basic knowledge of C#
TheRanger
TheRanger8/27/2022
try studying C# from $helloworld
TheRanger
TheRanger8/27/2022
literally the 2nd video teaches you that
TheRanger
TheRanger8/27/2022
1st video is just an introduction
Faraj
Faraj8/27/2022
I am so terrible at coding and creating projects. How do you know all that? How could solve this although it's not mentioned in the document?
TheRanger
TheRanger8/27/2022
what document?
Message Not Public

Sign In and Join Server To See

8/27/2022
Faraj
Faraj8/27/2022
I mean the Microsoft tutorial
TheRanger
TheRanger8/27/2022
it is mentioned
TheRanger
TheRanger8/27/2022
string concatenation is one of the fundamentals of C#
Message Not Public

Sign In and Join Server To See

8/27/2022
Faraj
Faraj8/27/2022
I've been watching C# tutorials for many months but I don't feel I'm doing any progress.
TheRanger
TheRanger8/27/2022
one of the first things you learn
Faraj
Faraj8/27/2022
Ok
Faraj
Faraj8/27/2022
I would like to ask you guys, do you guys recommend me to purchase a good course to be able to learn the fundemantls or should I just continue practice?
Faraj
Faraj8/27/2022
I feel like I'm wasting many days every time I encounter an issue of finding the right code to implement any project.
Message Not Public

Sign In and Join Server To See

8/27/2022
Message Not Public

Sign In and Join Server To See

8/27/2022
TheRanger
TheRanger8/27/2022
$helloworld is a good course
TheRanger
TheRanger8/27/2022
and it's free
Faraj
Faraj8/27/2022
Aha! Ok! Great to hear that, then I'll take your advice.
Faraj
Faraj8/27/2022
That's right
Message Not Public

Sign In and Join Server To See

8/27/2022
Faraj
Faraj8/27/2022
Ok! The problem with google is that you don't find the specific solution for your project.
Message Not Public

Sign In and Join Server To See

8/27/2022
Faraj
Faraj8/27/2022
Ok
Message Not Public

Sign In and Join Server To See

8/27/2022
Faraj
Faraj8/27/2022
Ok! I was thinking of this way too in order to shorten the lines of code.
Faraj
Faraj8/27/2022
Instead of adding all these. Console.WriteLine("Title: " + recipe1.Title);
Console.WriteLine("Type: " + recipe1.Type);
Console.WriteLine("Number: " + recipe1.Number);
Console.WriteLine("Difficulty: " + recipe1.Difficulty);
Console.WriteLine("Ingredients: " + recipe1.Ingredients
TheRanger
TheRanger8/27/2022
you could, with System.Reflection methods
Message Not Public

Sign In and Join Server To See

8/27/2022
TheRanger
TheRanger8/27/2022
it wont shorten the lines of code tho
Message Not Public

Sign In and Join Server To See

8/27/2022
TheRanger
TheRanger8/27/2022
        foreach(var property in recipe1.GetType().GetProperties())
        {
            Console.WriteLine($"{property.Name}: {property.GetValue(recipe1)}");
        }
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy