Hello.
In this lecture, we're going to talk about this topic 25.
What is released?
Let me take you on a journey back in time, a long, long time ago.
So before 2006, Dot Net was at version one.
It was still a pretty new framework because its initial release was in 2002.
The C-sharp language itself did not look much as it does now at this version of Dot Net.
There was no such thing as generics.
If you wanted to have a collection of numbers and a collection of strings, arrays were your best choice.
You couldn't count on things like the generic list of teams that can hold any type of items.
But as we learned in the lecture, What is an array?
Our can be pretty awkward.
They have fixed size.
They also don't provide any convenient methods like add or remove.
In other words, with arrays only, creating a complete, efficient and maintainable application that
made some real business needs could have been a pain in the neck.
Luckily, there was another way than using plain arrays.
The ArrayList type on our list is a dynamic collection, so a collection we can resize that can hold
any type of items.
And just to be clear, at the same time, single released can hold its strings, dates, times and anything
we want at the same moment.
In statically typed languages like C Sharp, this is at least weird, but how does it work?
Well, the released simply treats everything it holds as instances of system object type.
Here we can see that the element of index zero is simply an object.
After all, everything in C-sharp can be considered an object because every type is derived from the
object glass.
But there is a problem.
If the item we want to store in an array list is of a value type.
It must be boxed to be treated as object, which is a reference type.
Boxing is not a cheap operation.
It requires moving the value from the stock to the heap and creating a reference to it.
Also, at some point, we'll need to unbox this item to access the underlying value.
Finally, all boxed objects will need to be cleaned by the garbage collector.
We'll talk more about the performance of the unreleased later in this lecture.
Since are released can halt unagi of elements.
We don't really know what they are and how can we use them?
If I have a list of IANS, I know I can, for example, calculate the sum of them.
If I have a list of three things I know I can concatenate them, but what can I do with the elements
of an array list?
The truth is our list was almost never used to like this.
In most practical cases, it was holding elements of the same type.
That looks almost like generic lists, which again, were not present in the alternate before version
two.
But those variables are very problematic.
Let's say I wanted to create a method that calculates the sum of elements in the collection of numbers.
This method doesn't compile each element of the array waste is an object, so I can simply add it to
the result.
It may not be number at all.
It can as well be as Twig or Abu, so two added to the result.
I must first cast it and hope it will succeed.
Just to be sure, let us handle the invoked exception in this matter.
As you can see, we were forced to create a lot of code that would not be needed if we knew what types
exactly do we deal with.
In other words, if we're given a list of items instead of an are released, so we know the first big
disadvantage of at least we don't know what is stored inside.
So we must be ready for a lot of casting and error handling.
The other disadvantage is the performance that they mentioned before when storing value types are released.
They must all be boxed, which can impact the performance.
Very much so.
In this case, the natural question is when to use our lists of our lists.
Well, the answer is never, unless for some reason you must work in applications written in 2001.
But I honestly hope that you don't.
Even if you do consider upgrading the version of the botnet rather than working in this ancient technology,
you might then ask Why do we learn about this?
If it's not a big deal since 2006, first of all, the questions about our release are quite liked by
interviewers as they can be approached while discussion about static and dynamic typing.
What we learned more about in the lecture about the dynamic keyword.
Secondly, as much as I hope that you don't need to work with analysts, it may turn out that you have
to work with some legacy code that still uses them.
And then it's important that you know what you are dealing with.
Also, only recently, so in 2022, I've been working on a brand new application, or someone was using
our release for reasons they couldn't explain.
And as it turned out, it was mostly storing value types.
Changing them to lists not only made the development process much easier as the never ending costs and
handling could be omitted, but it also made the application over 25 percent faster.
There is one more case when using ARE may seem tempting when you actually need to store elements of
different types in a single collection.
But even then, it's better to use a list of objects as it provides more functionality, then are released
and will most likely be more consistent with the rest of the application.
Let's summarize on our list is a collection that can store elements of any type as it considers them
all instances of the system.
Object type already lists were widely used in older versions of C-sharp were the generics were not yet
available.
Nowadays, they should not be used as their performance is impacted by the fact that they need the box
value types.
During the interview, you can be asked What is the difference between an array on the East and an arrow
released on Arrow is a basic collection of fixed size that can store any declared type of elements.
The list is a dynamic collection.
It means its size can turn over time, and it's generic, so it can also store only declared type of
elements.
An unreleased is a dynamic collection that can store various types of elements at the same time as it
treats everything it stores as instances of the system.
Object type when to use are released over a generic list of D never unless you work with a very old
version of C-sharp, which did not support the generics.
But even if you do, you should rather upgrade dot net to a higher version, then work with release.
All right, that's it in this lecture.
Thanks for following along and see you in the next one.