Does C# support properties of array types?

Yes. Here's a simple example: using System;

class Class1

{

private string[] MyField;

public string[] MyProperty

{

get { return MyField; }

set { MyField = value; }

}

}

class MainClass

{

public static int Main(string[] args)

{

Class1 c = new Class1();

string[] arr = new string[] {"apple", "banana"};

c.MyProperty = arr;

Console.WriteLine(c.MyProperty[0]); // "apple"

return 0;

}

}

Showing Answers 1 - 3 of 3 Answers

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions