all groups > c# > january 2004 >
You're in the

c#

group:

What does this do? Object[0]


Re: What does this do? Object[0] Joe Mayo [MVP C#]
1/31/2004 2:07:09 PM
c#:


[quoted text, click to view]

Hi Chad,

It means you instantiated an array of type object with a Length of zero.

Joe
--
http://www.csharp-station.com

Re: What does this do? Object[0] Daniel O'Connell [C# MVP]
1/31/2004 3:42:07 PM

[quoted text, click to view]
Which, because it isn't immediately obvious, works because an array of
object(object[]) is still derived from object and will assign without
complaint.
[quoted text, click to view]

What does this do? Object[0] Chad Z. Hower aka Kudzu
1/31/2004 11:44:26 PM
Object MyOnject = new Object[0];

What does the [0] signify?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"


ELKNews - Get your free copy at http://www.atozedsoftware.com
Re: What does this do? Object[0] Chad Z. Hower aka Kudzu
2/1/2004 12:29:19 AM
"Joe Mayo [MVP C#]" <jmayo@nospamAtCSharpDashStation.com> wrote in
news:u8CXx4D6DHA.2576@TK2MSFTNGP11.phx.gbl:
[quoted text, click to view]

Aah. That makes sense. I guess the placement and the fact that I was looking
for a constructor in its place threw me.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"


ELKNews - Get your free copy at http://www.atozedsoftware.com
Re: What does this do? Object[0] Daniel O'Connell [C# MVP]
2/1/2004 3:08:07 AM

[quoted text, click to view]

As would I, the only use I could think of would be future proofing against
arrays == overload, and that is still a horrid construct.
object[] o = new object[0];

if (((object)o) == ((object)<whatever>))

seems far better to me.

[quoted text, click to view]

Re: What does this do? Object[0] Daniel O'Connell [C# MVP]
2/1/2004 4:25:39 AM

[quoted text, click to view]

Which sample was it? Something is very odd about that...

[quoted text, click to view]

Re: What does this do? Object[0] Daniel O'Connell [C# MVP]
2/1/2004 5:54:44 AM

[quoted text, click to view]

This is really strange, unless there is(was) a bug in object itself that I'm
not aware of this is a strange construct. An array of type object, even with
no members probably takes up more memory space than an empty object. I
really wonder what the point was...

[quoted text, click to view]

The callback is ok, although the ease of reading of this code sucks(for
non-colored code I like a little space inbetween comments and code), there
is a variable near the top of the method defined as:
AsyncCallback readImageCallback = new
AsyncCallback(ReadInImageCallback);

which is perfectly ok, a delegate is just an object afterall.
[quoted text, click to view]

Re: What does this do? Object[0] Jon Skeet [C# MVP]
2/1/2004 8:13:46 AM
[quoted text, click to view]

Indeed. If I saw a line of code like that in production source, I'd
definitely be suspicious - there'd have to be a good reason for the
variable not to be declared as object[] instead of object.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Re: What does this do? Object[0] Chad Z. Hower aka Kudzu
2/1/2004 11:55:43 AM
Jon Skeet [C# MVP] <skeet@pobox.com> wrote in
news:MPG.1a86c5921e09652798a02c@msnews.microsoft.com:
[quoted text, click to view]

Well I found it in MSDN in, in sample code. :)

I changed it to Object() anyways. It was only being used for a Monitor and
nothing else.

I suspet they were trying to save a few bytes, but it just doesnt seem a
clean approach. Some prior C developer probably.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"


ELKNews - Get your free copy at http://www.atozedsoftware.com
Re: What does this do? Object[0] Chad Z. Hower aka Kudzu
2/1/2004 1:53:39 PM
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
news:uacl72K6DHA.2692@TK2MSFTNGP09.phx.gbl:
[quoted text, click to view]

http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/cpguide/html/cpconASynchronousFileIO.asp

public static Object NumImagesMutex = new Object[0];

This line also looks suspicious:

fs.BeginRead(state.pixels, 0, numPixels, readImageCallback,
state);

Is it my imagination or is the call back not being referenced correctly? Such
has never compiled in my code...


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"


ELKNews - Get your free copy at http://www.atozedsoftware.com
Re: What does this do? Object[0] Chad Z. Hower aka Kudzu
2/1/2004 10:08:27 PM
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
news:#bSctoL6DHA.1020@tk2msftngp13.phx.gbl:
[quoted text, click to view]

You can change it to Object() and it works just fine. Its only used for a
Monitor lock. I suspect it was some old C coder trying to save some bytes,
assuming a 0 length array takes less space than an object.

[quoted text, click to view]

Aah - That I did not see. Thats poor code if you ask me - why would they
create a variable like that to be used once?

Also naming them nearly identical, with only really a case differnce and two
letters is a very poor choice too. I really hate the actualy use of case
senstivity in C#.



--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"


ELKNews - Get your free copy at http://www.atozedsoftware.com
Re: What does this do? Object[0] Jon Skeet [C# MVP]
2/2/2004 8:09:16 AM
[quoted text, click to view]

I often do that - just to break an otherwise complicated expression
into several smaller steps.

[quoted text, click to view]

Personally I love it - because it gives extra readability via
conventions. Admittedly I don't think this is a particularly good
choice of names, but I usually name properties and fields with only a
case difference:

string name;
public string Name
{
get { return name; }
}

etc.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Re: What does this do? Object[0] Daniel O'Connell [C# MVP]
2/2/2004 8:24:24 AM

[quoted text, click to view]

The naming doesn't bug me so much as the nasty commenting. It'd be far
easier to see if they had used some whitespace.
I use case sensitive naming rather often actually. It does take some getting
used to however(in VB it wasn't possible, and in C\C++ I used a camelCasing
style naming standard for globals, so it wasn't feasible there most of hte
time), but it has its upsides when you do get used to it.
[quoted text, click to view]

AddThis Social Bookmark Button