O'Reilly logo

Everyday Data Structures by William Smith

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Revisiting users logged in to a service

In Chapter 2, Arrays: Foundational Structures, we created an app to keep track of users logged into a web service, using an array as the underlying data structure containing the User objects. However, this design can be greatly improved upon by using a list data structure. Let's revisit the users logged into a service problem here, and by replacing the class array with a list, we will see that our original code is both abbreviated and more readable in most cases.

C#

In this example, we have replaced the User[] object with a List<User> object. Much of this refactor is obvious, but three lines of code should be noted. First, in the CanAddUser() method, we have replaced 15 lines of code with 2 lines of code by ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required