O
Ole Nielsby
Why is this?
I've stumbled on this restriction more than once, and I'd
like to know the philosophy behind it if there is one. I figure
I'd be less prone to make this error if I knew the reason.
Let me mention two cases where I wanted parameterless
struct constructors but could not get them.
1st, I needed sortable identity stamps on certain classes of
objects. I cooked this up:
struct IdentityStamp
{
public IdentityStamp()
{
lock (locker) this.stamp = seed++;
}
public readonly long stamp;
private static object locker = new object();
private static long seed = 0;
}
but it didn't compile and I had to change it, to
introduce an essentially unneeded parameter in
the constructor. I can't figure out why this had to
be so...
I've stumbled on this restriction more than once, and I'd
like to know the philosophy behind it if there is one. I figure
I'd be less prone to make this error if I knew the reason.
Let me mention two cases where I wanted parameterless
struct constructors but could not get them.
1st, I needed sortable identity stamps on certain classes of
objects. I cooked this up:
struct IdentityStamp
{
public IdentityStamp()
{
lock (locker) this.stamp = seed++;
}
public readonly long stamp;
private static object locker = new object();
private static long seed = 0;
}
but it didn't compile and I had to change it, to
introduce an essentially unneeded parameter in
the constructor. I can't figure out why this had to
be so...