Generic Collection in C#
-
What is Generic Collection? Why we use Generic Collection?
-
What is Generic Collection? Why we use Generic Collection?
-
What is Generic Collection? Why we use Generic Collection?
Are you faking some interview????? Why dont you search it in the google...????? Is it that hard to find???? There are million sites availing free tutorials on these topics.....
Have a Happy Coding.....
-
What is Generic Collection? Why we use Generic Collection?
Generic Collections (Array Lists) existed before non Generic (i.e. Lists). Obvously if you are storing a collection of one type of object a List is better suited to avoid casting. However you may have a situation where you want to maintain a collection of objects that are not necessarily the same object. They may have similar OO concepts (otherwise I have no idea why you would group them), but their actual TypeOf is different. In this case you would need to use the ArrayList to store the generic object. Again not sure why you would do this. The only time I am using ArrayList is when I have to go back to VS2003.
-
Generic Collections (Array Lists) existed before non Generic (i.e. Lists). Obvously if you are storing a collection of one type of object a List is better suited to avoid casting. However you may have a situation where you want to maintain a collection of objects that are not necessarily the same object. They may have similar OO concepts (otherwise I have no idea why you would group them), but their actual TypeOf is different. In this case you would need to use the ArrayList to store the generic object. Again not sure why you would do this. The only time I am using ArrayList is when I have to go back to VS2003.
Collin Jasnoch wrote:
Generic Collections (Array Lists) existed before non Generic (i.e. Lists).
You seem to have overloaded the word "generic" The ArrayList is not a Generic object in the OO sense of the word. To remove the ambiguity you may like to call them "general" rather than generic.
Collin Jasnoch wrote:
However you may have a situation where you want to maintain a collection of objects that are not necessarily the same object.
Did you mean "same _type of object". I've never found a situation where I would repeatedly store the same object in a list.
*Developer Day Scotland - Free community conference Delegate Registration Open
_
-
Collin Jasnoch wrote:
Generic Collections (Array Lists) existed before non Generic (i.e. Lists).
You seem to have overloaded the word "generic" The ArrayList is not a Generic object in the OO sense of the word. To remove the ambiguity you may like to call them "general" rather than generic.
Collin Jasnoch wrote:
However you may have a situation where you want to maintain a collection of objects that are not necessarily the same object.
Did you mean "same _type of object". I've never found a situation where I would repeatedly store the same object in a list.
*Developer Day Scotland - Free community conference Delegate Registration Open
_
Colin Angus Mackay wrote:
You seem to have overloaded the word "generic" The ArrayList is not a Generic object in the OO sense of the word. To remove the ambiguity you may like to call them "general" rather than generic
The arraylist is of type object. I used the word Generic because that is the word that was used in the question and I am assuming the question is about ArrayList. The word generic or general is irrelevant as long as my assumption is correct (stick with that same wording as the questionaire).
Colin Angus Mackay wrote:
Did you mean "same type of object". I've never found a situation where I would repeatedly store the same object in a list.
Yes I meant same object type (i.e. objects that are not of the same type stored in a collection). FYI you could have a situation where you want to store the same specific object in a list. The list does not keep copies but actual references. This is how you can keep ojects alive so the GC does not hit them. How you determine when to add and remove from the list would depend on what you are doing and what the data is. However, this was not what I was refering to.
-
Colin Angus Mackay wrote:
You seem to have overloaded the word "generic" The ArrayList is not a Generic object in the OO sense of the word. To remove the ambiguity you may like to call them "general" rather than generic
The arraylist is of type object. I used the word Generic because that is the word that was used in the question and I am assuming the question is about ArrayList. The word generic or general is irrelevant as long as my assumption is correct (stick with that same wording as the questionaire).
Colin Angus Mackay wrote:
Did you mean "same type of object". I've never found a situation where I would repeatedly store the same object in a list.
Yes I meant same object type (i.e. objects that are not of the same type stored in a collection). FYI you could have a situation where you want to store the same specific object in a list. The list does not keep copies but actual references. This is how you can keep ojects alive so the GC does not hit them. How you determine when to add and remove from the list would depend on what you are doing and what the data is. However, this was not what I was refering to.
"Generic Collections (Array Lists) existed before non Generic (i.e. Lists)" Actually, lists (List <T>) are generic and array lists are non-generic. You either got them mixed up, Or you're using the term "generic" to mean "any type". In any case, .NET uses the term to mean parameterized types.
Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro
-
Colin Angus Mackay wrote:
You seem to have overloaded the word "generic" The ArrayList is not a Generic object in the OO sense of the word. To remove the ambiguity you may like to call them "general" rather than generic
The arraylist is of type object. I used the word Generic because that is the word that was used in the question and I am assuming the question is about ArrayList. The word generic or general is irrelevant as long as my assumption is correct (stick with that same wording as the questionaire).
Colin Angus Mackay wrote:
Did you mean "same type of object". I've never found a situation where I would repeatedly store the same object in a list.
Yes I meant same object type (i.e. objects that are not of the same type stored in a collection). FYI you could have a situation where you want to store the same specific object in a list. The list does not keep copies but actual references. This is how you can keep ojects alive so the GC does not hit them. How you determine when to add and remove from the list would depend on what you are doing and what the data is. However, this was not what I was refering to.
Collin Jasnoch wrote:
The word generic or general is irrelevant
That is like saying "the word left or right is irrelevant". It isn't irrelevant. Generic has a very specific and well defined meaning in OO languages. If the OP used it in error then don't repeat the error. Use the correct term otherwise the OP will continue to use the word in error and cause more confusion later.
Collin Jasnoch wrote:
FYI you could have a situation where you want to store the same specific object in a list. The list does not keep copies but actual references.
Are you trying to teach me C#? I am well aware of this. I just said I've never found a situation where I would want to do this.
Collin Jasnoch wrote:
This is how you can keep ojects alive so the GC does not hit them.
Adding an object many times to the same list will not affect the way garbage collection works. Just one reference in the list is sufficient for the GC to ignore the object so long as the list itself is referenced.
*Developer Day Scotland - Free community conference Delegate Registration Open
-
Collin Jasnoch wrote:
The word generic or general is irrelevant
That is like saying "the word left or right is irrelevant". It isn't irrelevant. Generic has a very specific and well defined meaning in OO languages. If the OP used it in error then don't repeat the error. Use the correct term otherwise the OP will continue to use the word in error and cause more confusion later.
Collin Jasnoch wrote:
FYI you could have a situation where you want to store the same specific object in a list. The list does not keep copies but actual references.
Are you trying to teach me C#? I am well aware of this. I just said I've never found a situation where I would want to do this.
Collin Jasnoch wrote:
This is how you can keep ojects alive so the GC does not hit them.
Adding an object many times to the same list will not affect the way garbage collection works. Just one reference in the list is sufficient for the GC to ignore the object so long as the list itself is referenced.
*Developer Day Scotland - Free community conference Delegate Registration Open
Colin Angus Mackay wrote:
Are you trying to teach me C#? I am well aware of this. I just said I've never found a situation where I would want to do this.
Not trying to teach you. Just explaining why you would do this. You made it sound like it would be totally pointless. See bellow.
Colin Angus Mackay wrote:
Adding an object many times to the same list will not affect the way garbage collection works. Just one reference in the list is sufficient for the GC to ignore the object so long as the list itself is referenced.
It does when your algorithm removes from the list based on a lack of need for that object. i.e. when the need has diminished so have all references.
-
"Generic Collections (Array Lists) existed before non Generic (i.e. Lists)" Actually, lists (List <T>) are generic and array lists are non-generic. You either got them mixed up, Or you're using the term "generic" to mean "any type". In any case, .NET uses the term to mean parameterized types.
Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro
-
Collin Jasnoch wrote:
The word generic or general is irrelevant
That is like saying "the word left or right is irrelevant". It isn't irrelevant. Generic has a very specific and well defined meaning in OO languages. If the OP used it in error then don't repeat the error. Use the correct term otherwise the OP will continue to use the word in error and cause more confusion later.
Collin Jasnoch wrote:
FYI you could have a situation where you want to store the same specific object in a list. The list does not keep copies but actual references.
Are you trying to teach me C#? I am well aware of this. I just said I've never found a situation where I would want to do this.
Collin Jasnoch wrote:
This is how you can keep ojects alive so the GC does not hit them.
Adding an object many times to the same list will not affect the way garbage collection works. Just one reference in the list is sufficient for the GC to ignore the object so long as the list itself is referenced.
*Developer Day Scotland - Free community conference Delegate Registration Open
Colin Angus Mackay wrote:
Generic has a very specific and well defined meaning in OO languages.
I doubt that. It is rather difficult even to find an authoritative definition of "object oriented language". But if you do have an authoritative definition then I would for one would like to see it.