Hello guys, I would like to print out the property names and the values but can't find the right
BlazeBin - rmeikgewgcfo
A tool for sharing your source code with the world!
58 Replies
if ur on a Console Project just use Console.WriteLine to print the property names and their values
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
Unfortunately, I couldn't accomplish this!
on the same line?
Ok
Great! I'll give it a try.
Unfortunately! I got errors.
you need a reference of your recipe instance in order to access its members
eg
Ok
my example was just if you use that code inside Recipe's method
You're awesome bro, it worked just I expected 😃
Oh my god! I spent days trying to figure out this and you just solved it in minutes.
you're just missing the basic knowledge of C#
try studying C# from $helloworld
Written interactive course https://docs.microsoft.com/en-us/users/dotnet/collections/yz26f8y64n7k07
Videos https://dotnet.microsoft.com/learn/videos
literally the 2nd video teaches you that
1st video is just an introduction
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?
what document?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I mean the Microsoft tutorial
it is mentioned
string concatenation is one of the fundamentals of C#
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I've been watching C# tutorials for many months but I don't feel I'm doing any progress.
one of the first things you learn
Ok
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?
I feel like I'm wasting many days every time I encounter an issue of finding the right code to implement any project.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
$helloworld is a good course
Written interactive course https://docs.microsoft.com/en-us/users/dotnet/collections/yz26f8y64n7k07
Videos https://dotnet.microsoft.com/learn/videos
and it's free
Aha! Ok! Great to hear that, then I'll take your advice.
That's right
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Ok! The problem with google is that you don't find the specific solution for your project.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Ok
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Ok! I was thinking of this way too in order to shorten the lines of code.
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
you could, with System.Reflection methods
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
it wont shorten the lines of code tho
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
that will iterate through each property of recipe1, prints its name and its value
I typed instead in this way but it didn't seem right to me Console.WriteLine($"Title: " + recipe1.Title + "Type: " + recipe1.Type + "Number: " + recipe1.Number + "Difficulty: " + recipe1.Difficulty + "Ingredients: " + recipe1.Ingredients);
you can only write this code once, and all types of C# can use it
by just replacing recipe1 with a type of object that can be passed through an argument of a method
that will just print your data on the same line
yeah
u can put a
"\n"
or Environment.NewLine
between the string to append a new lineTheRanger#3357
REPL Result: Success
Console Output
Compile: 541.925ms | Execution: 27.277ms | React with ❌ to remove this embed.
Oh! Really, I didn't know that.
google won't really help if you're trying to search for a specific solution, just take the course i linked above
I tried to add the but didn't accomplish it
Console.WriteLine($"Title: " + recipe1.Title{Environment.NewLine} + "Type: " + recipe1.Type \n+ "Number: " + recipe1.Number + "Difficulty: " + recipe1.Difficulty + "Ingredients: " + recipe1.Ingredients);
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
\n it works if I add it like this "title: \n" but then the value property is not append with theTitle
Ok! I'll do that.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Ok
Title: Spicy-Sweet Glazed Salmon
Type: Lunch
Number: 2
I didn't get the rest like (Difficulty & Ingridents)
It's fixed now! I had to add the get; set; for both
As matus mentioned, what if I wanted to create recipe2, and recipe3 should I copy all these codes 2 times in order to create a total of 3 receipies?
If you do the same steps at multiple places, where the only things different is the variable, you will want to write a method for it
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
thats where you create methods to avoid writing repeated codes
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Ok! I guess I need to review again the same content that provides the feature that's required in a project.
Hey everyone, I have updated my code and I hope I got it right since it's meant to be a practicing project. https://paste.mod.gg/
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View