C
C#8mo 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
JakenVeina8mo ago
well, how does a foreach loop work? what does it need?
Paulvv
Paulvv8mo ago
a list of items
JakenVeina
JakenVeina8mo ago
how do you create a list of items?
Paulvv
Paulvv8mo ago
Got it working. I struggled with how list worked.
No description
JakenVeina
JakenVeina8mo 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
Paulvv8mo ago
Thanks for the help!
No description
Want results from more Discord servers?
Add your server
More Posts
❔ Newtonsoft JSON trying to serialize list of objects with a two dimensional array "shape" property.I'm getting some errors about additional characters being found in my json when trying to deserializHow to suppress all errors and warnings within namespace (or directory) using GlobalSuppressions.csI have a directory with generated API client code and it does not match coding standards configured ❔ DB and web API data potential desync- how to resolve?I have an app that will cross compare DB contract data to usage data fetched from a web API. The A❔ Load and debug c# scripts in runtimeHello everyone, i need load/reload c# scripts in runtime, and debug that scripts. I am try use this ❔ What to use instead of keycloak for built-in auth?I'm working on the backend for my app. The app was originally going to be a web app, so currently fo❔ Call API From Web API on Blazor ServerHello respected community members, I am new to Blazor Server and I am currently trying to fetch data❔ EF blowing up trying to insert a relationship that already existsCode and question are in the text file❔ Evaluating C# Expressions At RuntimeI am looking alternative ways to evaluate C# expression at runtime. I have used `Roslyn Scripting AP❔ ✅ running a c# program without opening visual studioHow do i run a c# program without opening visual studio on .net framework?❔ ✅ Verifying the purpose of Moq usage```csharp mockDatabase.Setup(db => db.GetUserName(It.IsAny<int>())) .Returns((int userId) => "Us