C
C#14mo ago
Paulvv

c# class

Extreme newbie question here. I want to use a foreach loop to Console.WriteLine all the objects. But how to i turn the "blog1, blog2 and blog3" into "blog" so that i could use the foreach loop?
No description
6 Replies
JakenVeina
JakenVeina14mo ago
well, how does a foreach loop work? what does it need?
Paulvv
PaulvvOP14mo ago
a list of items
JakenVeina
JakenVeina14mo ago
how do you create a list of items?
Paulvv
PaulvvOP14mo ago
Got it working. I struggled with how list worked.
No description
JakenVeina
JakenVeina14mo ago
perfect only thing I would do differently is make that an array
var blogs = new[]
{
blog1,
blog2,
blog3
};
var blogs = new[]
{
blog1,
blog2,
blog3
};
slightly more efficient List<T> will almost certainly allocate more memory than you actually need to store 3 references although, you can get around that by constructing the list with a specific capacity
var blogs = new List(capacity: 3)
{
blog1,
blog2,
blog3
};
var blogs = new List(capacity: 3)
{
blog1,
blog2,
blog3
};
but the array version is a little bit cleaner
Paulvv
PaulvvOP14mo ago
Thanks for the help!
No description
Want results from more Discord servers?
Add your server