How does C# support properties of array types?

 Posted by Kmandapalli on 1/22/2014 | Category: C# Interview questions | Views: 1896 | Points: 40
Answer:

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;
}
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response