471,108 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,108 software developers and data experts.

what is "new ClassName[ ... ]" (?)


I'm trying to re-construct missing classes in somebody else's code.

Salient points:

Dictionary<string, Projectprojects = new Dictionary<string, Project>();
....
WeeklyAggregation aggregation = new WeeklyAggregation();
....
aggregation.Project = new Project[projects.Count]; <-------- What is this?
projects.Values.CopyTo(aggregation.Project, 0);
foreach (projects project in aggregation.Project)
{
...
}

The classes I'm re-constructing from the rest of the code are:
- WeeklyAggregation
- Project

Can anybody explain and suggest how I should define parts relevant to the
code above, in the two classes?

Thank you.
Aug 19 '06 #1
4 1840

"bill tie" wrote...
>
I'm trying to re-construct missing classes in somebody else's code.

Salient points:

Dictionary<string, Projectprojects = new Dictionary<string, Project>();
...
WeeklyAggregation aggregation = new WeeklyAggregation();
...
aggregation.Project = new Project[projects.Count]; <--- What is this?
From the code you provided, we can deduce that the class WeeklyAggregation
has a member called "Project", which has the type Project[] (array of
project).

The size of that array will be the number of values in the Dictionary
project, at this point.

If we assume that the coder has followed normal naming guidelines, we can
assume that it's a property, which could be implemented as:

class WeeklyAggregation
{

private Project[] projects;

public Project[] Project
{
get { return projects; }
set { projects = value; }
}

...
}

The following line then simply copies the values of the Dictionary into the
array.
projects.Values.CopyTo(aggregation.Project, 0);
....and in the following statement, my guess is that you have misspelled
something...
foreach (projects project in aggregation.Project)
{
...
}
Shouldn't it be...

foreach (Project project in aggregation.Project)
{
...
}

?
The classes I'm re-constructing from the rest of the code are:
- WeeklyAggregation
- Project

Can anybody explain and suggest how I should define parts relevant to the
code above, in the two classes?
The thing we can deduce from the code you provided is what I wrote above,
i.e. that there must be a member "Project" in the class WeeklyAggregation.
The code doesn't say anything about the contents of the class Project.
Thank you.
You're welcome.

// Bjorn A

Aug 19 '06 #2
It should be noted that the OP's posted code will not compile. The
line:

aggregation.Project = new Project[projects.Count];

Declares an instance of Project, but tries to assign an array of Project
to it. There is also no variable name. It should be:

aggregation.Progject[] projects2 = new Project[projects.Count];
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bjorn Abelli" <bj**********@DoNotSpam.hotmail.comwrote in message
news:e8**************@TK2MSFTNGP05.phx.gbl...
>
"bill tie" wrote...
>>
I'm trying to re-construct missing classes in somebody else's code.

Salient points:

Dictionary<string, Projectprojects = new Dictionary<string, Project>();
...
WeeklyAggregation aggregation = new WeeklyAggregation();
...
aggregation.Project = new Project[projects.Count]; <--- What is this?

From the code you provided, we can deduce that the class WeeklyAggregation
has a member called "Project", which has the type Project[] (array of
project).

The size of that array will be the number of values in the Dictionary
project, at this point.

If we assume that the coder has followed normal naming guidelines, we can
assume that it's a property, which could be implemented as:

class WeeklyAggregation
{

private Project[] projects;

public Project[] Project
{
get { return projects; }
set { projects = value; }
}

...
}

The following line then simply copies the values of the Dictionary into
the array.
>projects.Values.CopyTo(aggregation.Project, 0);

...and in the following statement, my guess is that you have misspelled
something...
>foreach (projects project in aggregation.Project)
{
...
}

Shouldn't it be...

foreach (Project project in aggregation.Project)
{
...
}

?
>The classes I'm re-constructing from the rest of the code are:
- WeeklyAggregation
- Project

Can anybody explain and suggest how I should define parts relevant to the
code above, in the two classes?

The thing we can deduce from the code you provided is what I wrote above,
i.e. that there must be a member "Project" in the class WeeklyAggregation.
The code doesn't say anything about the contents of the class Project.
>Thank you.

You're welcome.

// Bjorn A

Aug 19 '06 #3
Nicholas Paldino [.NET/C# MVP] wrote:
It should be noted that the OP's posted code will not compile. The
line:

aggregation.Project = new Project[projects.Count];

Declares an instance of Project, but tries to assign an array of
Project to it.
Nonsense. If aggregation is an object, and aggregation.Project is a
property (or field) of type Project[], then the code compiles.
There is also no variable name. It should be:

aggregation.Progject[] projects2 = new Project[projects.Count];
If aggregation is a class name or namespace name, then this code would
compile, but if it's an object (a variable name), then this code will not
compile.

-cd

Aug 19 '06 #4
"Nicholas Paldino [.NET/C# MVP]" wrote...
It should be noted that the OP's posted code will not compile.
I agree that it will not compile, but not because of the reason you suggest.
The line:

aggregation.Project = new Project[projects.Count];

Declares an instance of Project, but tries to assign an
array of Project to it. There is also no variable name.
In the OP code "aggregation" is not a namespace or class name, but an
identifier for an instance of WeeklyAggregation, of which "Project" most
likely is a Property or other kind of member, i.e. "Project" *is* the
"variable".

That part of the code wouldn't cause any compilation error, which the
following probably would do:

>foreach (projects project in aggregation.Project)
{
...
}
....unless the class Project itself is defined something like this:

class Project : projects {...}

....which is most unlikely.

That part should most likely instead be...

foreach (Project project in aggregation.Project)
{
...
}

/// Bjorn A

Aug 20 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Philipp | last post: by
6 posts views Thread by dpr | last post: by
6 posts views Thread by peter.xiau | last post: by
36 posts views Thread by Pat | last post: by
30 posts views Thread by Medvedev | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.