Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am making a class Customer that has the following data members and properties:

private string customerName;
private double[] totalPurchasesLastThreeDays; //array of 3 elements that will hold the totals of how much the customer purchased for the past three days i.e. element[0] = 100, element[1] = 50, element[2] = 250

public string CustomerName
{
get { return customerName; }
set { customerName = value; }
}

public double[] TotalPurchasesLastThreeDays
{
?
}

How do I define the get and set for the array data member?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
203 views
Welcome To Ask or Share your Answers For Others

1 Answer

Do you want an indexer?

public double this[int i] {
  get { return totalPurchasesLastThreeDays[i]; }
  set { totalPurchasesLastThreeDays[i] = value; }
}

Because otherwise the question sounds a little weird, given that you already implemented a property in your code and are obviously capable of doing so.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...