Get/Set Property for Array

J

jp2msft

I've got a small array that is part of a class.

I know how to create the 8x8 array and fill the 8x8 array, but FxCop and
Microsoft's "Best Practices" frowns on declaring the array as "public".

So, how should one access array elements from outside of the class?
Obviously, 8x8=64 public properties for each array element is absurd.

Microsoft's DataTable has the Rows method that can be accessed as:

for (int i = 0; i < DataTable1.Rows.Count; i++)
Console.WriteLine("Row {0}: {1}", i, DataTable1.Rows[0].ToString());

My goal is to learn how to access arrays in my class similar to the
DataTable's array of values.

Thank you for your time,
Joe
 
M

Mr. Arnold

jp2msft said:
I've got a small array that is part of a class.

I know how to create the 8x8 array and fill the 8x8 array, but FxCop and
Microsoft's "Best Practices" frowns on declaring the array as "public".

So, how should one access array elements from outside of the class?
Obviously, 8x8=64 public properties for each array element is absurd.

Microsoft's DataTable has the Rows method that can be accessed as:

for (int i = 0; i < DataTable1.Rows.Count; i++)
Console.WriteLine("Row {0}: {1}", i, DataTable1.Rows[0].ToString());

My goal is to learn how to access arrays in my class similar to the
DataTable's array of values.


Here is an example.

private Arraylist _jpmsft = new Arraylist();


the public property

public Arraylist JP2MSFT
{
get { return _jp2msft; }
set { _jp2msft = value; }
}

You can do it this way too.

public ArrayList JP2MSFTS { get; set: }

If you had a class that held its own public properties (gets/sets) called it
Help.sc, and you needed them in a collection of strong typed classes then
it's this.

public List<Help> HELPS { get; set; }

Then it's JP2MSFTS.Add(object).

HELPS.Add(Help);

foreach(var help in HELPS)
{
string name = help.name;
}

You can do (for loop) using JP2MFST.Count or HELPS.Count.





__________ Information from ESET NOD32 Antivirus, version of virus signature database 4097 (20090522) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
M

Mr. Arnold

jp2msft said:
I've got a small array that is part of a class.

I know how to create the 8x8 array and fill the 8x8 array, but FxCop and
Microsoft's "Best Practices" frowns on declaring the array as "public".

So, how should one access array elements from outside of the class?
Obviously, 8x8=64 public properties for each array element is absurd.

Microsoft's DataTable has the Rows method that can be accessed as:

for (int i = 0; i < DataTable1.Rows.Count; i++)
Console.WriteLine("Row {0}: {1}", i, DataTable1.Rows[0].ToString());

My goal is to learn how to access arrays in my class similar to the
DataTable's array of values.


Here is an example.

private Arraylist _jpmsft = new Arraylist();


the public property

public Arraylist JP2MSFT
{
get { return _jp2msft; }
set { _jp2msft = value; }
}

You can do it this way too.

public ArrayList JP2MSFTS { get; set: }

If you had a class that held its own public properties (gets/sets) called it
Help.sc, and you needed them in a collection of strong typed classes then
it's this.

public List<Help> HELPS { get; set; }

Then it's JP2MSFTS.Add(object).

HELPS.Add(Help);

foreach(var help in HELPS)
{
string name = help.name;
}

You can do (for loop) using JP2MFST.Count or HELPS.Count.





__________ Information from ESET NOD32 Antivirus, version of virus signature database 4097 (20090522) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
B

Ben Voigt [C++ MVP]

Mr. Arnold said:
jp2msft said:
I've got a small array that is part of a class.

I know how to create the 8x8 array and fill the 8x8 array, but FxCop and
Microsoft's "Best Practices" frowns on declaring the array as "public".

So, how should one access array elements from outside of the class?
Obviously, 8x8=64 public properties for each array element is absurd.

Microsoft's DataTable has the Rows method that can be accessed as:

for (int i = 0; i < DataTable1.Rows.Count; i++)
Console.WriteLine("Row {0}: {1}", i, DataTable1.Rows[0].ToString());

My goal is to learn how to access arrays in my class similar to the
DataTable's array of values.


Here is an example.

private Arraylist _jpmsft = new Arraylist();


What's this Arraylist? Never run into it before. And if you mean
System.Collections.ArrayList, that's been dead since Visual Studio 2005.
 
B

Ben Voigt [C++ MVP]

Mr. Arnold said:
jp2msft said:
I've got a small array that is part of a class.

I know how to create the 8x8 array and fill the 8x8 array, but FxCop and
Microsoft's "Best Practices" frowns on declaring the array as "public".

So, how should one access array elements from outside of the class?
Obviously, 8x8=64 public properties for each array element is absurd.

Microsoft's DataTable has the Rows method that can be accessed as:

for (int i = 0; i < DataTable1.Rows.Count; i++)
Console.WriteLine("Row {0}: {1}", i, DataTable1.Rows[0].ToString());

My goal is to learn how to access arrays in my class similar to the
DataTable's array of values.


Here is an example.

private Arraylist _jpmsft = new Arraylist();


What's this Arraylist? Never run into it before. And if you mean
System.Collections.ArrayList, that's been dead since Visual Studio 2005.
 
M

Mr. Arnold

Ben Voigt said:
Mr. Arnold said:
jp2msft said:
I've got a small array that is part of a class.

I know how to create the 8x8 array and fill the 8x8 array, but FxCop and
Microsoft's "Best Practices" frowns on declaring the array as "public".

So, how should one access array elements from outside of the class?
Obviously, 8x8=64 public properties for each array element is absurd.

Microsoft's DataTable has the Rows method that can be accessed as:

for (int i = 0; i < DataTable1.Rows.Count; i++)
Console.WriteLine("Row {0}: {1}", i, DataTable1.Rows[0].ToString());

My goal is to learn how to access arrays in my class similar to the
DataTable's array of values.


Here is an example.

private Arraylist _jpmsft = new Arraylist();


What's this Arraylist? Never run into it before. And if you mean
System.Collections.ArrayList, that's been dead since Visual Studio 2005.


The ArrayList has been dead since VS 2005, when I just instantiated an
ArrayList() object in VS 2008 from the System.Collections?

Just because you don't use something does that make it dead. If I have a
need to use an Arraylist, then I going to use one. You may have a different
opinion. <G>




__________ Information from ESET NOD32 Antivirus, version of virus signature database 4098 (20090522) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
M

Mr. Arnold

Ben Voigt said:
Mr. Arnold said:
jp2msft said:
I've got a small array that is part of a class.

I know how to create the 8x8 array and fill the 8x8 array, but FxCop and
Microsoft's "Best Practices" frowns on declaring the array as "public".

So, how should one access array elements from outside of the class?
Obviously, 8x8=64 public properties for each array element is absurd.

Microsoft's DataTable has the Rows method that can be accessed as:

for (int i = 0; i < DataTable1.Rows.Count; i++)
Console.WriteLine("Row {0}: {1}", i, DataTable1.Rows[0].ToString());

My goal is to learn how to access arrays in my class similar to the
DataTable's array of values.


Here is an example.

private Arraylist _jpmsft = new Arraylist();


What's this Arraylist? Never run into it before. And if you mean
System.Collections.ArrayList, that's been dead since Visual Studio 2005.


The ArrayList has been dead since VS 2005, when I just instantiated an
ArrayList() object in VS 2008 from the System.Collections?

Just because you don't use something does that make it dead. If I have a
need to use an Arraylist, then I going to use one. You may have a different
opinion. <G>




__________ Information from ESET NOD32 Antivirus, version of virus signature database 4098 (20090522) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
B

Ben Voigt [C++ MVP]

Here is an example.
The ArrayList has been dead since VS 2005, when I just instantiated an
ArrayList() object in VS 2008 from the System.Collections?

Just because you don't use something does that make it dead. If I have a
need to use an Arraylist, then I going to use one. You may have a
different opinion. <G>

It's a fact that you can't get case sensitivity right when your error is
pointed out to you, and it's a fact that the generic List<T> is superior to
ArrayList in every way I can think of (type safety, performance, removing
the broken "threadsafe" wrapper, etc).
 
B

Ben Voigt [C++ MVP]

Here is an example.
The ArrayList has been dead since VS 2005, when I just instantiated an
ArrayList() object in VS 2008 from the System.Collections?

Just because you don't use something does that make it dead. If I have a
need to use an Arraylist, then I going to use one. You may have a
different opinion. <G>

It's a fact that you can't get case sensitivity right when your error is
pointed out to you, and it's a fact that the generic List<T> is superior to
ArrayList in every way I can think of (type safety, performance, removing
the broken "threadsafe" wrapper, etc).
 
B

Ben Voigt [C++ MVP]

Mr. Arnold said:
So? If I have a needed to use an ArrayList(), I am going to use one.

Sounds good to me. But I have never run into a situation where List<T>
couldn't be used and I needed an ArrayList.

So maybe you could give an example of a need to use an ArrayList.
 
B

Ben Voigt [C++ MVP]

Mr. Arnold" <"Mr Arnold said:
So what if I wanted to bring back two different serialized objects
back from a WCF service without making two calls?

The easiest way to do that would be to use and ArrayList that is not
type safe as a container to hold both objects and cast them back to
their type on the other side..

What if I wanted to have an int that has a count of how many objects
there were in the list followed by the objects, then another int
telling how many objects followed by its objects, casting back on the
other side as I walked the ArrayList(). You can do that with an
ArrayList().

You don't need ArrayList, List<object> will work just fine.

In the first instance you can use a more specific type if for example both
objects return the same interface.

For the second, sounds like you should be using List<List<T>>, so the
deserializer will construct all the sublists for you. Walking that list is
just an extra chance for things to break.

Any other example of a need for ArrayList?
 
M

Mr. Arnold

Ben Voigt said:
You don't need ArrayList, List<object> will work just fine.

In the first instance you can use a more specific type if for example both
objects return the same interface.

This doesn't meet my requirement, which I am not going to get into.
For the second, sounds like you should be using List<List<T>>, so the
deserializer will construct all the sublists for you. Walking that list
is just an extra chance for things to break.

I already know this, which I have done this currently and in the past with
the ADO.NET Entity Framework and the entities.

In addition to this, with business objects as an explicit serialized data
contract on the server side of a WCF solution, where as, the MVP presenter
is the client of a WCF service, with the BLL, Workflow, and DAL projects
Any other example of a need for ArrayList?

The bottom line here is that you're never going to convince be that an
ArrayList() is obsolete, until I see something in the IDE stating that an
ArrayList() is obsolete or warnings after a compile stating that an
ArrayList() is obsolete and use something else instead.

I don't see this. You point it out.

If I choose to use an ArrayList(), then so be it.

All this you're trying to point out is moot as far as I am concerned.


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4129 (20090604) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top