PC Review


Reply
Thread Tools Rate Thread

Arrays and inheritence

 
 
Magnus.Moraberg@gmail.com
Guest
Posts: n/a
 
      24th Jun 2008
Hi,

I have a class called StatusType.

public class StatusType: ICloneable, IComparable<StatusType>
{
int id; // id as stored in statusType table
public int Id
{
get { return id; }
}
....


I also have a class called StatusTypes which looks something like this
-

public class StatusTypes: ICloneable, IEnumerable
{
StatusType[] statusTypes;

public StatusType this[int statusTypeId] // Indexer
declaration
{
get
{
foreach (StatusType statusType in statusTypes)
if (statusType.Id == statusTypeId)
return statusType;
return null;
}
}

public int Length{get { return statusTypes.Length; }}

// returns "P/F/A" for Passed, Failed, Aborted status types
public string StringRepresentation
{
get
{
string returnString = "";

if (statusTypes.Length > 0)
returnString =
statusTypes[0].NameInitial.ToString();

for(int i=1;i<statusTypes.Length;i++)
returnString += @"/" +
statusTypes[i].NameInitial.ToString();

return returnString;
}
}

// populate from the statusType table
public StatusTypes(dataSet.statusTypeDataTable statusType)
{
statusTypes = new StatusType[statusType.Count];

int index = 0;
foreach (DataRow statusTypeDataRow in statusType.Rows)
statusTypes[index++] = new
StatusType(statusTypeDataRow as dataSet.statusTypeRow);
Array.Sort(statusTypes);
}

public object Clone()
{
StatusTypes clonedStatusTypes =
(StatusTypes)this.MemberwiseClone();

clonedStatusTypes.statusTypes = new
StatusType[statusTypes.Length];

int index = 0;
foreach (StatusType statusType in statusTypes)
clonedStatusTypes.statusTypes[index++] =
(StatusType)statusType.Clone();

return clonedStatusTypes;
}

IEnumerator IEnumerable.GetEnumerator() { return
statusTypes.GetEnumerator(); }

}

Since I'm still learning C#, is this implementation reasonable? One
thing I'm wondering about is the fact that I have a public accessor to
StatusType:id. The fact is that this is only accessed by StatusTypes.
It feels to me that StatusTypes should have access to private or
protected members of StatusType since this feel like a kind of
inheritance to me. How would I implement this?

Thanks,

Barry.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting native arrays to managed arrays Bob Altman Microsoft VC .NET 8 27th Feb 2008 11:33 PM
Trouble with arrays (transferring values between two arrays) Keith R Microsoft Excel Programming 4 14th Nov 2007 12:00 AM
Jagged Arrays Problem - How to Assign Arrays to an Array Zigs Microsoft Excel Programming 3 11th Apr 2007 01:39 AM
Working with ranges in arrays... or an introduction to arrays =?Utf-8?B?R2xlbg==?= Microsoft Excel Programming 5 10th Sep 2006 08:32 AM
Arrays - declaration, adding values to arrays and calculation Maxi Microsoft Excel Programming 1 17th Aug 2006 04:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:56 AM.