DEV Community

Scott Slatton
Scott Slatton

Posted on

2

C# Generic Collections

One thing I’ve heard before and definitely am guilty of repeating before knowing the meaning of, is the statement: “Javascript doesn’t have arrays it has lists”. I’ve always understood this to basically mean nothing because “functionally, they’re the same” and when you’re learning Javascript for the first time, this can be a good philosophy to have because you don’t get bogged down with theory and can focus your attention on just building things. When I began delving into C# however, starting to use it on a daily basis, this philosophy caught up with me quickly. I’ve known for quite a long time that arrays in languages other than Javascript have a fixed length that you must declare at some point. It was incredibly intimidating and I struggled to understand how you work around this limitation. I’d like to share with you my “Aha!” moment I had when I finally understood that learning data structures and when to use them became so pivotal to creating proper, functional and optimized code.

C# has a namespace in the .NET library called System.Collections.Generic and it’s within here that you can find your lists, stacks, and queues. These are typically data structures you have to build out manually in Javascript. You can instantiate any of these like a normal object declaration.

List<T> grades = new List<T>();

Sidenote: If this is the first time you’re seeing the it’s a generic type parameter, meaning you can fill in that parameter with any type recognized by the compiler like string or double.

Lists do obviously come with a higher memory cost than normal arrays but solves our issue of needing to know how many items are going to be in our array if you’re not sure . My favorite thing about using these built in data structures is that they come with methods built in as well. You can easily implement a binary search on a list by calling .BinarySearch() on the List object instance.

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay