Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring a collection of objects using object vs Object [duplicate]

Possible Duplicate:
String vs string in C#

I have a simple scenario where I am binding a grid to a collection of objects that will be stored in a list. The question that I was wondering is what is the best practice for declaring a list of objects?

IList<object> myCollection;

or

IList<Object> myCollection;

I've read some code standards articles and a lot of people suggest using String vs string so I was wondering if the same rule applies here and why? What is different about the two methods (if anything) and what kind of performance gains are there for doing it one way vs the other.

This grid is part of a custom control where the list is exposed as a property that will be bound to the grid.

like image 422
jsmith Avatar asked Jan 29 '26 07:01

jsmith


2 Answers

  • There's no semantic difference.
  • There's no performance difference at all.
  • Both string and object are keywords of the C# language and resolve to System.String and System.Object classes respectively.

The theoretical advantage of using object over Object is that you are lowering the dependency on the Base Class Library. However, since BCL is a core part of .NET Framework the practical “advantage” is avoiding using System; in simple cases. Such “advantage” is IMHO disputable.

like image 80
Ondrej Tucny Avatar answered Jan 30 '26 20:01

Ondrej Tucny


There's no difference, the lowercase object is an alias for the Object class, as the lower case string is an alias for the String class, int for Int32 etc.

already answered in the best way:

String vs string in C#

like image 42
Mark W Avatar answered Jan 30 '26 20:01

Mark W