74 Replies
What's the question?
oh i deleted it on accident
when i run it should save the names in a list and the type
and later on print it out
but when i run it
it doesnt ask about the cat
and when it should print out list and types
it only prints out dog
the number of times
the inputs were about cats and dogs
Okay there are couple of bugs here

Can you send the code as text though instead of screen shots, it would be easier to explain
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
If your code is too long, post it to: https://paste.mod.gg/First this here
This checks how many items are already in the list, it doesn't check the number you provided in the prompt
ooooh
Second the
else
is for the second if
meaning it doesn't care whether dogs.count is > 20 or is -1dog1.Count_Dog
Third what even is
Count_dog
and Count_cat
?number of dogs they inputed
Why not just do
You shouldn't create a new instance of
Dog
and Cat
to hold the number
That doesn't make sense, right?yea
TryParse
never heard of that
TryParse returns a bool, true if success otherwise false, it
out
s parsed value
so i dont need this?
i just need list
You need to get the user's input
But you don't need to use a property declared in an instance of
Dog
and Cat
to hold the countsi need to get only type now
Also
an
if
or if else
or else
Without curly braces means only the next statement is under it's scope
Which means, it only cares about this part
type of what?the type of the animal
Lastly
Iterates until
i
is larger than or equals cats.Count
but cats.Count
is obv 0 because nothing was added to it, and if something was added to cats
list, you'll run into an infinite loop, because with each addition, cats.Count
increases aswelland save it in a list so it prints out {name}, {dog type}
Okay, then
1 - Get count of dogs that the user wants to add
2 - Iterate to fill the list with the dogs info
3 - In the for loop, prompt the user for dog's name and type
4 - Iterate over the list and print out the info
and one more question using . TryParse how can i get dog Type information
TryParse
pattern is used to parse something, is dog type an enum, is it a number?Oh
so i just ReadLine normally
Well, it depends, do you trust the user to really provide a type?
What if the user simply pressed enter without entering the dog type?
i mean
i dont have to check that
ig
i just need to fix parts where i used dog1 and cat1
to use readline do i do inside the do brackets
or
after while
loop
What do you mean?

nvm i did it
Yeah, I missed a parenthesis
and the part i made the mistake asking name and type of the dog
for (int i = 0; i < ?; i++)
Well what do think should go here?
number of the dogs

for (int i = 0; i < dogs.Count; i++) ;
What do you think would be the value of
dogs.Count
it should be dogCount
You mean
dogs.Count
equals dogCount
?no like we put the number of dogs in dogCount
and the dogs.Count would be 0
Right
and than i readline and add it in a list
Spot 

i feel smart but i am not
Well, you understood the problem and started to fix it, don't be hard on yourself!
and adding in a list dogs.Add(Name1);
What's the type of
dogs
variable?
Then what
items
can it hold?string
Do you know generics?
using System.Collections.Generic;
that?
No, the concept of generics in c#
oh
hm
i dont think so
Alright, give a read to this
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/generics
and to $helloworld as well
But a TLDR for this problem
List<int>
means a List can hold items of type int
, List<bool>
means it holds bool
Generic classes and methods
Learn about generics. Generic types maximize code reuse, type safety, and performance, and are commonly used to create collection classes.
Written interactive course https://learn.microsoft.com/en-us/users/dotnet/collections/yz26f8y64n7k07
Videos https://dotnet.microsoft.com/learn/videos
oooh
ik that
i didnt know what ment
meant
still ty imma read it
and the main question when i add it in a list
i want it to print out {name} {type}, {name} {type}
do i need a seperate list
No you don't need a seperate list
and print it out with a loop and adding [i+1] to the elements
oh
ngl i always forget things in c# bc in python everything was easy
Yeah C# can be confusing coming from a python background
They have very different ways of doing 

question reading the input
do i need to do var name1
or string
var
just implicitly declares the variable without having you explicitly typing the type of the variable
name1
is still string
if it's assigned a string variableoh yea
ty
I would change the variable name though
name1
doesn't sound good imoName
>>>
and asking the type do i do inside or outside the for loop
bc last time i did it outside it didnt work
What do you mean?
Okay okay, that's wrong
for (int i = 0; i < dogCount; i++) ;
is an empty for loopLet's take it a step by step
Can you explain what each line does?
first loop which goes through until the inputted number
write name your dog x times
reads it
adds in a list
as name
second loop goes through until the inputted number
gets input
reades it as string type
adds to list as Type
Okay, do you know about scopes?