Inline Initializing C# Lists - Quick Tip @WorldOfZeroDevelopment
Inline Initializing C# Lists - Quick Tip  @WorldOfZeroDevelopment
Uploaded February 2019 | Updated November 2026, 3 days ago
C# includes a method for initializing Lists that means you do not need to repeatedly `Add("foo")` throughout your code. This allows you to specify a set of items immediately after the Lists constructor that causes the items to be sequentially added to the list after its created for you. This works for most collection types including Arrays and Lists.

Here's an example of what constructing a list like this might look like.

```csharp
// Note: replace angled brackets with correct character!
var myList = new List⟨string⟩() { "this", "is", "a", "test" };
```

Doing this traditionally would look like this:

```csharp
// Note: replace angled brackets with correct character!
var myList = new List⟨string⟩();
myList.Add("this");
myList.Add("is");
myList.Add("a");
myList.Add("test");
```

This trick also works with Dictionary's! Here's how: youtu.be/lFsgmxzw7IU

Join the World of Zero Discord server: discord.gg/hU5Kq2u
Inline Initializing C# Lists - Quick TipRecreating Particle Effects with Game Objects in Unity 3DBuilding a Custom Node in Unitys Shader GraphRuntime C# Scripting in Unity UI - The Roslyn Compiler in UnityUsing ContextMenu and ContextMenuItem in Unity 3DSwinging with the Asteroids VR Grappling Hook - Part 2Using Bash .bashrc and .profile Files to Initialize Your TerminalBuilding a Custom Dice Model with OpenSCADSpherical Gravity in UnityRotating the Flight Controller - Lets Make a Side Scrolling Shooter - Part 2Validate Unity Inspector Input with OnValidate - Quick TipRunning a Minecraft Server in Docker
World of Zero |

Inline Initializing C# Lists - Quick Tip

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER