Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
public uint[] BIG_Hash { get; set; }
but the last two lines need to be inside a method, right? How would those methods look like?public uint[] BIG_Hash { get; set; }
...
obj.BIG_Hash = new uint[5]; // set
uint[] temp = obj.BIG_Hash; // get
I remember I did something like this months ago but I cannot remember how it is done. It is a special case for special variables. You have to add some more code.
but the last two lines need to be inside a method, right? How would those methods look like?
In C#, you get and set variables like this:
private string name;
public string Name
{
get
{
return name;
}
set
{
if(name == null)
throw new ArgumentException();
name = value; // value is a special keyword
}
}
public void Test()
{
String s = Name; // since Name is on the right, it calls the "get accessor"
Name = "al mac"; // since Name is on the left, it calls the "set accessor"
}
// automatically creates a private variable for "Age" and wraps it in a property, you just don't see it
public int Age
{
get;
set;
}
// Now.. for an array
private byte[] someArray = new byte[1024];
public byte[] SomeArray
{
get
{
return someArray;
}
set
{
someArray = value;
}
}
public byte[] SomeArray = new byte[1024];
^ Agreed.
Is an array truly the ideal way to expose data in your scenario?
Arrays are managed collections.
In C#, you get and set variables like this:
In C#, you create properties like this:
Arrays are managed collections.
Which collection class doesn't?
How does a collection differ from a data structure that implements IEnumerable?Technically, Arrays in C# are a data structure and are not a collection in regards to .NET.
How does a collection differ from a data structure that implements IEnumerable?
How does a collection differ from a data structure that implements IEnumerable?
Because ICollection inherits IEnumerable, not the other way around. (Though, to be fair, collections in the .NET framework have some Liskov violations)
List<T> has plenty of methods which are not defined by IEnumerable.
Which ones? How?
Are you asking which methods are exposed by List but not defined by IEnumerable? MSDN has an exhaustive page, but .add() for one....
No no no, you said collections in .NET have Liskov violations. Can you be more specific? Which ones and how is it that they do not work? I'm having a hard time thinking of a violation here.
ReadOnlyCollection inherits List, implements ICollection, throws on .Add and .Remove.
Hmm originally I agreed with you, but under careful look of the interfaces, I'm not so sure.
ReadOnlyCollection (which is new in the newest .NET 4.5) extends from List<T>. Therefore, it implements IList which does have a IsReadOnly property and clearly says that it throws a NotSupportedException if .Add and .Remove are used when it is read only. ICollection does not specify any add or remove methods (which IList extends)
It doesn't seem to be an unreasonable design to have a IsReadOnly property, but I do agree that the design is a bit strange. The ICollection interface isn't all that useful on its own. It's a bit weird that ReadOnlyCollection is actually a List. Also compare ICollection and ICollection<T>. ICollection<T> implements a lot more of the IList methods that make it more useful.
Anyway, I'm not sure that it is a good idea to have diverging inheritance paths either, for example, ICollection and IReadOnlyCollection. One post I saw suggested an IWriteable<T> and IReadable<T> and have IList implement both but that sounds like it could be more hassle than its worth. Hmm..