471,315 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,315 software developers and data experts.

(Delphi-like) Limited-bounds-types?

As far as I can see, there is no similar way of replicating the
following Delphi-code in C#... Is that true?

type
IntRange = -5..5;
CharRange = 'a'..'z';

TColors = (Red, White, Green, Blue, Yellow);
ColorRange = White..Blue;

Jan 9 '06 #1
21 1805
matko,

No, there is not. In C# you would have to place explicit checks on your
methods/properties to validate that the values are in range.

However, this is not that difficult to do.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"matko" <ma*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
As far as I can see, there is no similar way of replicating the
following Delphi-code in C#... Is that true?

type
IntRange = -5..5;
CharRange = 'a'..'z';

TColors = (Red, White, Green, Blue, Yellow);
ColorRange = White..Blue;

Jan 9 '06 #2
Hehe. Yes, I know it's not that difficult! ;)
It would, however, just be nice if there was a way...

Thanks for the reply!

Nicholas Paldino [.NET/C# MVP] wrote:
matko,

No, there is not. In C# you would have to place explicit checks on your
methods/properties to validate that the values are in range.

However, this is not that difficult to do.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"matko" <ma*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
As far as I can see, there is no similar way of replicating the
following Delphi-code in C#... Is that true?

type
IntRange = -5..5;
CharRange = 'a'..'z';

TColors = (Red, White, Green, Blue, Yellow);
ColorRange = White..Blue;


Jan 9 '06 #3
matko wrote:
Hehe. Yes, I know it's not that difficult! ;)
It would, however, just be nice if there was a way...

Thanks for the reply!


You may well be able to write a generic one in .NET 2.0, if that's any
help. I don't know that it would really be worth it though...

Jon

Jan 9 '06 #4
There is a way to do this in .NET 1.1 and before. You can create
context-bound objects which will allow you to intercept calls and perform
actions (you would indicate your range through attributes). However,
generally, this isn't something you want to do only because there is some
overhead in processing the call stack into a message based format (which is
what the context bound interception model does).

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
matko wrote:
Hehe. Yes, I know it's not that difficult! ;)
It would, however, just be nice if there was a way...

Thanks for the reply!


You may well be able to write a generic one in .NET 2.0, if that's any
help. I don't know that it would really be worth it though...

Jon

Jan 9 '06 #5
I don't know much about .NET 2.0 (yet), but couldn't you create an
IntRange struct in .NET 1.1 that would enforce a range? It wouldn't be
too difficult to do, and would incur minimum overhead.

The only downside is that you would have to declare a separate struct
for each base type, and define all of the implicit and explicit casts,
and math operators, etc, for the new struct.

Well... maybe I should qualify that "not too difficult to do": not too
hard on the brain, but lots of typing. :-)

Jan 9 '06 #6
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
There is a way to do this in .NET 1.1 and before. You can create
context-bound objects which will allow you to intercept calls and perform
actions (you would indicate your range through attributes). However,
generally, this isn't something you want to do only because there is some
overhead in processing the call stack into a message based format (which is
what the context bound interception model does).


Well, you could do it in 1.1 without context-bound objects, by
converting the enum to its base type value and doing a range check on
that. It's just nicer with generics :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 9 '06 #7
Bruce Wood <br*******@canada.com> wrote:
I don't know much about .NET 2.0 (yet), but couldn't you create an
IntRange struct in .NET 1.1 that would enforce a range? It wouldn't be
too difficult to do, and would incur minimum overhead.

The only downside is that you would have to declare a separate struct
for each base type, and define all of the implicit and explicit casts,
and math operators, etc, for the new struct.

Well... maybe I should qualify that "not too difficult to do": not too
hard on the brain, but lots of typing. :-)


Here's a .NET 2.0 version (and test case). The .NET 1.1 version would
either require boxing or a separate type for each enum etc:

using System;

public class Range<T> where T : struct, IComparable
{
T min, max;

public Range(T min, T max)
{
this.min = min;
this.max = max;
}

public bool Includes(T value)
{
return min.CompareTo(value) <= 0 &&
max.CompareTo(value) >= 0;
}
}

enum Foo
{
First,
Second,
Third,
Fourth,
Fifth
}

class Test
{
static void Main()
{
Range<Foo> range = new Range<Foo>(Foo.Second, Foo.Fourth);

foreach (Foo f in Enum.GetValues(typeof(Foo)))
{
Console.WriteLine ("{0} - {1}", f, range.Includes(f));
}
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 9 '06 #8
Matko,

You could handle these special cases in static methods of a class that is
named appropriately. For example, the enumeration could be handled like
this
public class MyColors
{
public enum TypeEnum : byte
{
Unknown = 0,
Red,
White,
Green,
Blue,
Yellow
};

public static bool IsColorInTheFlag(TypeEnum eColor)
{
switch(eColor)
{
case TypeEnum.Red :
case TypeEnum.White:
case TypeEnum.Blue:
return true;
default :
return false;
}
}

public static bool IsValidColor(byte clr)
{
return ((clr > 0) && Enum.IsDefined(typeof(MyColors.TypeEnum), clr));
}

}

Dave

"matko" <ma*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
As far as I can see, there is no similar way of replicating the
following Delphi-code in C#... Is that true?

type
IntRange = -5..5;
CharRange = 'a'..'z';

TColors = (Red, White, Green, Blue, Yellow);
ColorRange = White..Blue;

Jan 9 '06 #9
Generics doesn't really do much here (yes, compile time checking against
the type passed in is nice), but I think that the thing the OP is trying to
get at is that he doesn't want to perform a check manually, he wants to say
somehow that this is his range, and have the runtime enforce it.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Bruce Wood <br*******@canada.com> wrote:
I don't know much about .NET 2.0 (yet), but couldn't you create an
IntRange struct in .NET 1.1 that would enforce a range? It wouldn't be
too difficult to do, and would incur minimum overhead.

The only downside is that you would have to declare a separate struct
for each base type, and define all of the implicit and explicit casts,
and math operators, etc, for the new struct.

Well... maybe I should qualify that "not too difficult to do": not too
hard on the brain, but lots of typing. :-)


Here's a .NET 2.0 version (and test case). The .NET 1.1 version would
either require boxing or a separate type for each enum etc:

using System;

public class Range<T> where T : struct, IComparable
{
T min, max;

public Range(T min, T max)
{
this.min = min;
this.max = max;
}

public bool Includes(T value)
{
return min.CompareTo(value) <= 0 &&
max.CompareTo(value) >= 0;
}
}

enum Foo
{
First,
Second,
Third,
Fourth,
Fifth
}

class Test
{
static void Main()
{
Range<Foo> range = new Range<Foo>(Foo.Second, Foo.Fourth);

foreach (Foo f in Enum.GetValues(typeof(Foo)))
{
Console.WriteLine ("{0} - {1}", f, range.Includes(f));
}
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jan 9 '06 #10
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
Generics doesn't really do much here (yes, compile time checking against
the type passed in is nice)
It also prevents boxing.
but I think that the thing the OP is trying to
get at is that he doesn't want to perform a check manually, he wants to say
somehow that this is his range, and have the runtime enforce it.


Well, I'm not sure I see much difference between:

ColorRange = White..Blue;
and
Range<Color> colorRange = new Range<Color>(Color.White, Color.Blue);

(I'd have expected new Range(Color.White, Color.Blue) to work, but it
doesn't - I need to check the spec to see why.)

The former is certainly neater, but you still get to find out
inclusivity etc - and it probably wouldn't be too hard to give it a bit
more functionality if required.

Maybe I'm missing some more functionality - but all the examples given
can be done with the Range type I gave.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 9 '06 #11
Jon,

I'm not an expert on Delphi, but my impression is that the OP wanted
something more. Yes, the range class does work, but that's not the point.

With context bound objects, you can do something like:

public void MyFunction([Range(0, 5)] int value)
{
// Do something with value here.
// NO need to check against range, since it will have
// already been checked by the context bound object.
}

This is a ficticuous context bound attribute, used to display the point.
This way, his function can assume the check passed, otherwise, the
interception code which the Range attribute handles would throw an
exception.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
Generics doesn't really do much here (yes, compile time checking
against
the type passed in is nice)


It also prevents boxing.
but I think that the thing the OP is trying to
get at is that he doesn't want to perform a check manually, he wants to
say
somehow that this is his range, and have the runtime enforce it.


Well, I'm not sure I see much difference between:

ColorRange = White..Blue;
and
Range<Color> colorRange = new Range<Color>(Color.White, Color.Blue);

(I'd have expected new Range(Color.White, Color.Blue) to work, but it
doesn't - I need to check the spec to see why.)

The former is certainly neater, but you still get to find out
inclusivity etc - and it probably wouldn't be too hard to give it a bit
more functionality if required.

Maybe I'm missing some more functionality - but all the examples given
can be done with the Range type I gave.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jan 9 '06 #12
PRECISELY!

Wouldn't it be nice to have such (easily applicable) functionality in
C#?

Nicholas Paldino [.NET/C# MVP] wrote:
Jon,

I'm not an expert on Delphi, but my impression is that the OP wanted
something more. Yes, the range class does work, but that's not the point.

With context bound objects, you can do something like:

public void MyFunction([Range(0, 5)] int value)
{
// Do something with value here.
// NO need to check against range, since it will have
// already been checked by the context bound object.
}

This is a ficticuous context bound attribute, used to display the point.
This way, his function can assume the check passed, otherwise, the
interception code which the Range attribute handles would throw an
exception.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
Generics doesn't really do much here (yes, compile time checking
against
the type passed in is nice)


It also prevents boxing.
but I think that the thing the OP is trying to
get at is that he doesn't want to perform a check manually, he wants to
say
somehow that this is his range, and have the runtime enforce it.


Well, I'm not sure I see much difference between:

ColorRange = White..Blue;
and
Range<Color> colorRange = new Range<Color>(Color.White, Color.Blue);

(I'd have expected new Range(Color.White, Color.Blue) to work, but it
doesn't - I need to check the spec to see why.)

The former is certainly neater, but you still get to find out
inclusivity etc - and it probably wouldn't be too hard to give it a bit
more functionality if required.

Maybe I'm missing some more functionality - but all the examples given
can be done with the Range type I gave.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Jan 9 '06 #13
matko,

Unfortunately, you would have to do something with ContextBoundObjects
in order to do this. It will hinder performance, so it is not a feasibile
solution for this kind of thing (since it would be done so often).

However, if you want more information on this, check out the following
MSDN magazine article:

http://msdn.microsoft.com/msdnmag/is...ContextsinNET/
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"matko" <ma*****@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
PRECISELY!

Wouldn't it be nice to have such (easily applicable) functionality in
C#?

Nicholas Paldino [.NET/C# MVP] wrote:
Jon,

I'm not an expert on Delphi, but my impression is that the OP wanted
something more. Yes, the range class does work, but that's not the
point.

With context bound objects, you can do something like:

public void MyFunction([Range(0, 5)] int value)
{
// Do something with value here.
// NO need to check against range, since it will have
// already been checked by the context bound object.
}

This is a ficticuous context bound attribute, used to display the
point.
This way, his function can assume the check passed, otherwise, the
interception code which the Range attribute handles would throw an
exception.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
> Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
>> Generics doesn't really do much here (yes, compile time checking
>> against
>> the type passed in is nice)
>
> It also prevents boxing.
>
>> but I think that the thing the OP is trying to
>> get at is that he doesn't want to perform a check manually, he wants
>> to
>> say
>> somehow that this is his range, and have the runtime enforce it.
>
> Well, I'm not sure I see much difference between:
>
> ColorRange = White..Blue;
> and
> Range<Color> colorRange = new Range<Color>(Color.White, Color.Blue);
>
> (I'd have expected new Range(Color.White, Color.Blue) to work, but it
> doesn't - I need to check the spec to see why.)
>
> The former is certainly neater, but you still get to find out
> inclusivity etc - and it probably wouldn't be too hard to give it a bit
> more functionality if required.
>
> Maybe I'm missing some more functionality - but all the examples given
> can be done with the Range type I gave.
>
> --
> Jon Skeet - <sk***@pobox.com>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too

Jan 9 '06 #14
Bingo!

I want the compiler or/and the runtime-environment to detect
bounds-related errors.
That such (limited-bounds) type declaration is allowed in Delphi is
very... pleasant!

Nicholas Paldino [.NET/C# MVP] wrote:
Generics doesn't really do much here (yes, compile time checking against
the type passed in is nice), but I think that the thing the OP is trying to
get at is that he doesn't want to perform a check manually, he wants to say
somehow that this is his range, and have the runtime enforce it.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Bruce Wood <br*******@canada.com> wrote:
I don't know much about .NET 2.0 (yet), but couldn't you create an
IntRange struct in .NET 1.1 that would enforce a range? It wouldn't be
too difficult to do, and would incur minimum overhead.

The only downside is that you would have to declare a separate struct
for each base type, and define all of the implicit and explicit casts,
and math operators, etc, for the new struct.

Well... maybe I should qualify that "not too difficult to do": not too
hard on the brain, but lots of typing. :-)


Here's a .NET 2.0 version (and test case). The .NET 1.1 version would
either require boxing or a separate type for each enum etc:

using System;

public class Range<T> where T : struct, IComparable
{
T min, max;

public Range(T min, T max)
{
this.min = min;
this.max = max;
}

public bool Includes(T value)
{
return min.CompareTo(value) <= 0 &&
max.CompareTo(value) >= 0;
}
}

enum Foo
{
First,
Second,
Third,
Fourth,
Fifth
}

class Test
{
static void Main()
{
Range<Foo> range = new Range<Foo>(Foo.Second, Foo.Fourth);

foreach (Foo f in Enum.GetValues(typeof(Foo)))
{
Console.WriteLine ("{0} - {1}", f, range.Includes(f));
}
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Jan 9 '06 #15
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
Jon,

I'm not an expert on Delphi, but my impression is that the OP wanted
something more. Yes, the range class does work, but that's not the point.

With context bound objects, you can do something like:

public void MyFunction([Range(0, 5)] int value)
{
// Do something with value here.
// NO need to check against range, since it will have
// already been checked by the context bound object.
}

This is a ficticuous context bound attribute, used to display the point.
This way, his function can assume the check passed, otherwise, the
interception code which the Range attribute handles would throw an
exception.


Ah, right, I'm with you. Yes, that would be handy. There are lots of
things like that which sometimes are part of design-by-contract,
sometimes part of AOP etc. Hopefully Anders is looking into those for
C# 4.0...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 9 '06 #16
Not from what I have seen. Anders is NOT a big fan of AOP in the least.
Method interception - MAYBE, but AOP, definitely not.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
Jon,

I'm not an expert on Delphi, but my impression is that the OP wanted
something more. Yes, the range class does work, but that's not the
point.

With context bound objects, you can do something like:

public void MyFunction([Range(0, 5)] int value)
{
// Do something with value here.
// NO need to check against range, since it will have
// already been checked by the context bound object.
}

This is a ficticuous context bound attribute, used to display the
point.
This way, his function can assume the check passed, otherwise, the
interception code which the Range attribute handles would throw an
exception.


Ah, right, I'm with you. Yes, that would be handy. There are lots of
things like that which sometimes are part of design-by-contract,
sometimes part of AOP etc. Hopefully Anders is looking into those for
C# 4.0...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jan 9 '06 #17
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
Not from what I have seen. Anders is NOT a big fan of AOP in the least.
Method interception - MAYBE, but AOP, definitely not.


Well, that might be due to current implementations, limitations etc. I
suspect he can see the benefits of being able to specify cross-cutting
concerns, etc, even if he's not happy with how it's all done at the
moment.

I wouldn't be surprised if something came out which at least tackled
the same kinds of issues that AOP does, even if it's not immediately
recognisable as an AOP implementation.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 9 '06 #18
Well, as I pointed out you _could_ create a struct to wrap another
value type and then have that struct do the bounds checking on every
assignment, because each assignment from a base type would really be an
implicit conversion operation. It would invovle significant overhead
(every assignment would really be a method call), and it would also be
a heck of a lot of code to write, as you would have to reproduce every
operator, including all implicit and explicit conversions, of the
native type in your struct wrapper.

This isn't just a Delphi thing. I remember this back in 1980 with
Pascal, so it's not as though it's some fancy new AOP-related thing.
It's probably just another of those features that Anders and the C#
team saw as offering some benefits, but not sufficient benefit to
justify adding yet more syntax to the language.

You could ask for the feature, anyway... it's been in enough other
languages (Pascal and now Delphi) that it's obviously not some flash in
the pan.

Jan 10 '06 #19
Oh, sure.
Delphi _is_, more-or-less (more more than less), Pascal.

Anyway, I'd love this to be a part of C#. It's neat and helpful
functionality.

Thanks for all comments ;)

Bruce Wood wrote:
Well, as I pointed out you _could_ create a struct to wrap another
value type and then have that struct do the bounds checking on every
assignment, because each assignment from a base type would really be an
implicit conversion operation. It would invovle significant overhead
(every assignment would really be a method call), and it would also be
a heck of a lot of code to write, as you would have to reproduce every
operator, including all implicit and explicit conversions, of the
native type in your struct wrapper.

This isn't just a Delphi thing. I remember this back in 1980 with
Pascal, so it's not as though it's some fancy new AOP-related thing.
It's probably just another of those features that Anders and the C#
team saw as offering some benefits, but not sufficient benefit to
justify adding yet more syntax to the language.

You could ask for the feature, anyway... it's been in enough other
languages (Pascal and now Delphi) that it's obviously not some flash in
the pan.


Jan 10 '06 #20
It sure helps that the guy that probably invented this functionality for
Delphi/Object Pascal is the same guy in charge of C# (Anders)...

I also perpetually salivate for Delphi-like sets to be included as part of
C#... I really miss constructs like "if (a in [2,4,5,10-20]) then ..."

gabriel

"matko" <ma*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Oh, sure.
Delphi _is_, more-or-less (more more than less), Pascal.

Anyway, I'd love this to be a part of C#. It's neat and helpful
functionality.

Thanks for all comments ;)

Bruce Wood wrote:
Well, as I pointed out you _could_ create a struct to wrap another
value type and then have that struct do the bounds checking on every
assignment, because each assignment from a base type would really be an
implicit conversion operation. It would invovle significant overhead
(every assignment would really be a method call), and it would also be
a heck of a lot of code to write, as you would have to reproduce every
operator, including all implicit and explicit conversions, of the
native type in your struct wrapper.

This isn't just a Delphi thing. I remember this back in 1980 with
Pascal, so it's not as though it's some fancy new AOP-related thing.
It's probably just another of those features that Anders and the C#
team saw as offering some benefits, but not sufficient benefit to
justify adding yet more syntax to the language.

You could ask for the feature, anyway... it's been in enough other
languages (Pascal and now Delphi) that it's obviously not some flash in
the pan.

Jan 10 '06 #21
Is that so?
Well, I love Delphi and as soon as I saw C# (which was not long ago) I
fell in love. Sounds so dramatic, but C# is a really nice programming
language.

Gabriel Magaña skrev:
It sure helps that the guy that probably invented this functionality for
Delphi/Object Pascal is the same guy in charge of C# (Anders)...

I also perpetually salivate for Delphi-like sets to be included as part of
C#... I really miss constructs like "if (a in [2,4,5,10-20]) then ..."

gabriel

"matko" <ma*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Oh, sure.
Delphi _is_, more-or-less (more more than less), Pascal.

Anyway, I'd love this to be a part of C#. It's neat and helpful
functionality.

Thanks for all comments ;)

Bruce Wood wrote:
Well, as I pointed out you _could_ create a struct to wrap another
value type and then have that struct do the bounds checking on every
assignment, because each assignment from a base type would really be an
implicit conversion operation. It would invovle significant overhead
(every assignment would really be a method call), and it would also be
a heck of a lot of code to write, as you would have to reproduce every
operator, including all implicit and explicit conversions, of the
native type in your struct wrapper.

This isn't just a Delphi thing. I remember this back in 1980 with
Pascal, so it's not as though it's some fancy new AOP-related thing.
It's probably just another of those features that Anders and the C#
team saw as offering some benefits, but not sufficient benefit to
justify adding yet more syntax to the language.

You could ask for the feature, anyway... it's been in enough other
languages (Pascal and now Delphi) that it's obviously not some flash in
the pan.


Jan 11 '06 #22

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.