How do I add myself an avatar from the public avatar library?
Why properties cannot be used as ref or out arguments
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What can I do?
• What to Read?
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Ñîîáùåñòâà
• Talxy Chat
• Horoscope
• Online
 
Çàðåãèñòðèðóéñÿ!

QAIX > .Net Development > Why properties cannot be used as ref or out arguments 11 March 2008 10:23:37

  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Moderators:

Why properties cannot be used as ref or out arguments

Dean Cleaver 11 March 2008 10:23:37
 I can understand ref arguments, because they might not be set on
passing, but I can't figure out why they can't be used as out arguments?

Any thoughts?

Dino

===================­================
This list is hosted by DevelopMentor http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Ryan Heath 10 March 2008 12:28:04 permanent link ]
 Because properties are implemented underneath as functions.
get_PropName
set_PropName

A ref argument cannot point to a func, and if it did, it would point
to the wrong function in any case.

ref arg needs the passing value; it would need the get_PropName function for it.
but ref arg needs to set the value as well; it would need the
set_PropName function for it.

HTH
// Ryan

On Mon, Mar 10, 2008 at 10:20 AM, Dean Cleaver
<dean.cleaver@xcept­ionsoftware.com> wrote:
I can understand ref arguments, because they might not be set on
passing, but I can't figure out why they can't be used as out arguments?
Any thoughts?
Dino
===================­================
This list is hosted by DevelopMentor(R) http://www.develop.­com
View archives and manage your subscription(s) at http://discuss.deve­lop.com

===================­================
This list is hosted by DevelopMentor® http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Jon Skeet 10 March 2008 12:32:08 permanent link ]
 Dean Cleaver wrote:
I can understand ref arguments, because they might not be set on
passing, but I can't figure out why they can't be used as out arguments?
Any thoughts?

That's not the reason for not being able to use them as ref.

When you pass a parameter by out/ref, you're effectively passing an
address that the called method can use as the variable address. It can
treat it like any other variable in terms of storing and fetching values
directly (subject to definite assignment rules for out, of course).

Properties don't work like this - they're not slots in memory, to be
arbitrarily accessed.


Note that if you use properties for out/ref parameters in VB, basically
a temporary variable is created, *that* is passed by out/ref, and the
property is set appropriately after method has completed.

Jon

===================­================
This list is hosted by DevelopMentor® http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Dean Cleaver 10 March 2008 12:33:48 permanent link ]
 Ah. Yes. Didn't think of the actual mechanics of how it presented the
properties behind it all. Thank you.

Is a shame though - or is there any way I can get around it using
delegates? I have a function that I require to set one of two
properties, and return a 3rd?

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Ryan Heath
Sent: Monday, 10 March 2008 22:28
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

Because properties are implemented underneath as functions.
get_PropName
set_PropName

A ref argument cannot point to a func, and if it did, it would point
to the wrong function in any case.

ref arg needs the passing value; it would need the get_PropName function
for it.
but ref arg needs to set the value as well; it would need the
set_PropName function for it.

HTH
// Ryan

On Mon, Mar 10, 2008 at 10:20 AM, Dean Cleaver
<dean.cleaver@xcept­ionsoftware.com> wrote:
I can understand ref arguments, because they might not be set on
passing, but I can't figure out why they can't be used as out
arguments?
Any thoughts?
Dino
===================­================
This list is hosted by DevelopMentor(R) http://www.develop.­com
View archives and manage your subscription(s) at
http://discuss.deve­lop.com

===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com

View archives and manage your subscription(s) at
http://discuss.deve­lop.com

===================­================
This list is hosted by DevelopMentor http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Dean Cleaver 10 March 2008 12:44:10 permanent link ]
 Yeah - getting my head around it now. Sadly, it's not VB I wanted it
for.

Is a shame- looks like I will have to declare 2 variables, pass them in,
and then analyse the returned responses to achieve what I want - takes
the "ideal" 1 line call to about 7 or 8 at least - was trying to
encapsulate a call, but it might not be feasible.

Dino

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Jon Skeet
Sent: Monday, 10 March 2008 22:32
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

Dean Cleaver wrote:
I can understand ref arguments, because they might not be set on
passing, but I can't figure out why they can't be used as out
arguments?
Any thoughts?

That's not the reason for not being able to use them as ref.

When you pass a parameter by out/ref, you're effectively passing an
address that the called method can use as the variable address. It can
treat it like any other variable in terms of storing and fetching values
directly (subject to definite assignment rules for out, of course).

Properties don't work like this - they're not slots in memory, to be
arbitrarily accessed.


Note that if you use properties for out/ref parameters in VB, basically
a temporary variable is created, *that* is passed by out/ref, and the
property is set appropriately after method has completed.

Jon

===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com

View archives and manage your subscription(s) at
http://discuss.deve­lop.com

===================­================
This list is hosted by DevelopMentor http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Jon Skeet 10 March 2008 12:45:36 permanent link ]
 Dean Cleaver wrote:
Ah. Yes. Didn't think of the actual mechanics of how it presented the
properties behind it all. Thank you.
Is a shame though - or is there any way I can get around it using
delegates? I have a function that I require to set one of two
properties, and return a 3rd?

Is it sufficiently general that you could create an interface with the
properties in, and then pass an implementation of that interface into
the method?

You certainly *could* do it with delegates, but it would feel a little ugly.

Jon

===================­================
This list is hosted by DevelopMentor® http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Jon Skeet 10 March 2008 12:55:39 permanent link ]
 Dean Cleaver wrote:
Yeah - getting my head around it now. Sadly, it's not VB I wanted it
for.
Is a shame- looks like I will have to declare 2 variables, pass them in,
and then analyse the returned responses to achieve what I want - takes
the "ideal" 1 line call to about 7 or 8 at least - was trying to
encapsulate a call, but it might not be feasible.

Sounds like an argument for tuple return types:

(FirstNameProperty,­ LastNameProperty) = SplitName(FullName)­;

:)­

(Can you tell I've been learning Erlang? ;)

I've no idea how much work is required either in terms of language
design or CLR modifications to support this - I suspect it would be
feasible in "language only" but a lot more elegant with CLR integration.

Jon

===================­================
This list is hosted by DevelopMentor® http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Silky 10 March 2008 13:33:51 permanent link ]
 -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, Mar 10, 2008 at 8:55 PM, Jon Skeet wrote:
Dean Cleaver wrote:
Yeah - getting my head around it now. Sadly, it's not VB I wanted it
for.
Is a shame- looks like I will have to declare 2 variables, pass them in,
and then analyse the returned responses to achieve what I want - takes
the "ideal" 1 line call to about 7 or 8 at least - was trying to
encapsulate a call, but it might not be feasible.
Sounds like an argument for tuple return types:
(FirstNameProperty,­ LastNameProperty) = SplitName(FullName)­;
:)­
(Can you tell I've been learning Erlang? ;)
I've no idea how much work is required either in terms of language
design or CLR modifications to support this - I suspect it would be
feasible in "language only" but a lot more elegant with CLR integration.

Yeah I'd like this too, but I have vague feelings that it can be done
with an anonymous class. Is there such a thing? probably not. But I do
note that creating 'quick' classes is a bit easier in 3.0 ... multiple
assignments from functions would be useful though.

(a, b, c) = foo(m);

public (string, int, double) foo (int m) { }

- --
http://lets.coozi.c­om.au/

There's not a problem I can't fix, because I can do it in the mix.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: http://firegpg.tuxf­amily.org

iQEVAwUBR9UOgE4i+6w­d5ptaAQIgDwf8CWLmxkF­owVzVq5Qm96Zyx1JHH+b­Xfyjr
pus/FVvJpoPPRKjZfj8­gk/fDJUeIhN4YcAJ3uoP­Co1yQfl2qZV1Tefz0JYc­mfzOo
k+v4m4CYnKL1QjYqM3v­fHd9J95lx2FCNUmjqmV4­qJxyAn/xvqA54PmrqBF/­LImFs
92HBOPInWTJ/4e8ME9w­knkc9enHtduNqLk9wOO8­3trulFRzpfBmPS26R9xl­qrBx3
sK1TCREXyUFvRAgsE+l­2QjRnFoIL46iBbu/uzId­V6eUChfYKa7K8I3G3Cpn­8oYCk
lU8bBn0c5MvXmPEotT4­SIJxX0SWbwfQCXFPqOCv­MBclRgqinUk1vOw==
=J28+
-----END PGP SIGNATURE-----

===================­================
This list is hosted by DevelopMentor® http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Jon Skeet 10 March 2008 13:37:17 permanent link ]
 silky wrote:
I've no idea how much work is required either in terms of language
design or CLR modifications to support this - I suspect it would be
feasible in "language only" but a lot more elegant with CLR integration.
Yeah I'd like this too, but I have vague feelings that it can be done
with an anonymous class. Is there such a thing?

There are indeed anonymous types in C# 3, but they aren't easily
returned from a method in a strongly typed way.

Jon

===================­================
This list is hosted by DevelopMentor® http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Dean Cleaver 10 March 2008 13:45:31 permanent link ]
 Problem is my variables are of differing types... not that I can tell
from your code snippet, but It seems they are expected to be the same
type?

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Jon Skeet
Sent: Monday, 10 March 2008 22:56
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

Dean Cleaver wrote:
Yeah - getting my head around it now. Sadly, it's not VB I wanted it
for.
Is a shame- looks like I will have to declare 2 variables, pass them
in,
and then analyse the returned responses to achieve what I want - takes
the "ideal" 1 line call to about 7 or 8 at least - was trying to
encapsulate a call, but it might not be feasible.

Sounds like an argument for tuple return types:

(FirstNameProperty,­ LastNameProperty) = SplitName(FullName)­;

:)­

(Can you tell I've been learning Erlang? ;)

I've no idea how much work is required either in terms of language
design or CLR modifications to support this - I suspect it would be
feasible in "language only" but a lot more elegant with CLR integration.

Jon

===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com

View archives and manage your subscription(s) at
http://discuss.deve­lop.com

===================­================
This list is hosted by DevelopMentor http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Dean Cleaver 10 March 2008 13:52:45 permanent link ]
 I don't think an interface would work, as this is generic - for example,
on one data entry screen, I might have 10 textboxes with strings, 3 with
dates etc and I would want to call these generic functions 10 time for
the string properties, and 3 times for the date properties - so there's
no way my class could implement a single interface for it. And there
will be a few places where I want to call the same generic functions, so
1 interface with multiple properties won't work either.

Dino

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Jon Skeet
Sent: Monday, 10 March 2008 22:46
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

Dean Cleaver wrote:
Ah. Yes. Didn't think of the actual mechanics of how it presented the
properties behind it all. Thank you.
Is a shame though - or is there any way I can get around it using
delegates? I have a function that I require to set one of two
properties, and return a 3rd?

Is it sufficiently general that you could create an interface with the
properties in, and then pass an implementation of that interface into
the method?

You certainly *could* do it with delegates, but it would feel a little
ugly.

Jon

===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com

View archives and manage your subscription(s) at
http://discuss.deve­lop.com

===================­================
This list is hosted by DevelopMentor http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Barry Kelly 10 March 2008 13:57:42 permanent link ]
 Dean Cleaver <dean.cleaver@XCEPT­IONSOFTWARE.COM> wrote:

Problem is my variables are of differing types... not that I can tell
from your code snippet, but It seems they are expected to be the same
type?

Erlang is dynamically typed. However, more generally, tuples are
structurally typed, and each field can have a separate type - that's
what makes them different to arrays. In statically typed functional
languages, where tuples are common, the type of e.g. ("Barry", "Kelly")
would be (String, String).

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Jon Skeet
Sent: Monday, 10 March 2008 22:56
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments
Dean Cleaver wrote:
Yeah - getting my head around it now. Sadly, it's not VB I wanted it
for.
Is a shame- looks like I will have to declare 2 variables, pass them
in,
and then analyse the returned responses to achieve what I want - takes
the "ideal" 1 line call to about 7 or 8 at least - was trying to
encapsulate a call, but it might not be feasible.
Sounds like an argument for tuple return types:
(FirstNameProperty,­ LastNameProperty) = SplitName(FullName)­;
:)­
(Can you tell I've been learning Erlang? ;)
I've no idea how much work is required either in terms of language
design or CLR modifications to support this - I suspect it would be
feasible in "language only" but a lot more elegant with CLR integration.
Jon
===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com
View archives and manage your subscription(s) at
===================­================
This list is hosted by DevelopMentor® http://www.develop.­com
View archives and manage your subscription(s) at http://discuss.deve­lop.com

-- Barry

--
http://barrkel.blog­spot.com/

===================­================
This list is hosted by DevelopMentor® http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Dean Cleaver 10 March 2008 14:00:11 permanent link ]
 Heh - cool - but as this website is entirely C#, I can't see Erlang
being of use, but the concept is interesting :)­

Dino

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Barry
Kelly
Sent: Monday, 10 March 2008 23:58
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

Dean Cleaver <dean.cleaver@XCEPT­IONSOFTWARE.COM> wrote:

Problem is my variables are of differing types... not that I can tell
from your code snippet, but It seems they are expected to be the same
type?

Erlang is dynamically typed. However, more generally, tuples are
structurally typed, and each field can have a separate type - that's
what makes them different to arrays. In statically typed functional
languages, where tuples are common, the type of e.g. ("Barry", "Kelly")
would be (String, String).

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Jon
Skeet
Sent: Monday, 10 March 2008 22:56
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments
Dean Cleaver wrote:
Yeah - getting my head around it now. Sadly, it's not VB I wanted it
for.
Is a shame- looks like I will have to declare 2 variables, pass them
in,
and then analyse the returned responses to achieve what I want -
takes
the "ideal" 1 line call to about 7 or 8 at least - was trying to
encapsulate a call, but it might not be feasible.
Sounds like an argument for tuple return types:
(FirstNameProperty,­ LastNameProperty) = SplitName(FullName)­;
:)­
(Can you tell I've been learning Erlang? ;)
I've no idea how much work is required either in terms of language
design or CLR modifications to support this - I suspect it would be
feasible in "language only" but a lot more elegant with CLR
integration.
Jon
===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com
View archives and manage your subscription(s) at
===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com
View archives and manage your subscription(s) at
http://discuss.deve­lop.com

-- Barry

--
http://barrkel.blog­spot.com/

===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com

View archives and manage your subscription(s) at
http://discuss.deve­lop.com

===================­================
This list is hosted by DevelopMentor http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Barry Kelly 10 March 2008 14:04:41 permanent link ]
 Dean Cleaver <dean.cleaver@XCEPT­IONSOFTWARE.COM> wrote:

I can understand ref arguments, because they might not be set on
passing, but I can't figure out why they can't be used as out arguments?

You've read the other stuff which indicates the why.

You might consider passing anonymous methods instead, though. It ought
to be fairly concise with the new lambda syntax. Something like:

---8<---
using System;

class App
{
static void Main()
{
FrobRef(() => MyProp, x => MyProp = x);
FrobOut(x => MyProp = x);
}

delegate T Getter<T>();
delegate void Setter<T>(T value);

static void FrobRef(Getter<int>­ g, Setter<int> s)
{
s(g() * 2);
}

static void FrobOut(Setter<int>­ s)
{
s(42);
}

static int MyProp
{
get
{
Console.WriteLine("­Reading");
return 12;
}
set
{
Console.WriteLine("­Writing: {0}", value);
}
}
}
--->8---

You might even "improve" this by creating a simple PropertyRef class
with a single property Value, that delegates getting and setting to the
one or two delegates passed to its constructor, etc.

-- Barry

--
http://barrkel.blog­spot.com/

===================­================
This list is hosted by DevelopMentor http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Shawn Wildermuth 10 March 2008 14:06:24 permanent link ]
 I know its not terribly efficient, but couldn't you return a simple struct
or anonymous type with the multiple pieces of information?

Thanks,

Shawn Wildermuth
http://adoguy.com
http://wildermuthco­nsulting.com
http://geekdinners.­com
Microsoft MVP (C#), MCSD.NET, Author and Speaker

The Silverlight Tour is coming to a city near you!

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Dean Cleaver
Sent: Monday, March 10, 2008 7:00 AM
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

Heh - cool - but as this website is entirely C#, I can't see Erlang
being of use, but the concept is interesting :)­

Dino

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Barry
Kelly
Sent: Monday, 10 March 2008 23:58
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

Dean Cleaver <dean.cleaver@XCEPT­IONSOFTWARE.COM> wrote:

Problem is my variables are of differing types... not that I can tell
from your code snippet, but It seems they are expected to be the same
type?

Erlang is dynamically typed. However, more generally, tuples are
structurally typed, and each field can have a separate type - that's
what makes them different to arrays. In statically typed functional
languages, where tuples are common, the type of e.g. ("Barry", "Kelly")
would be (String, String).

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Jon
Skeet
Sent: Monday, 10 March 2008 22:56
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments
Dean Cleaver wrote:
Yeah - getting my head around it now. Sadly, it's not VB I wanted it
for.
Is a shame- looks like I will have to declare 2 variables, pass them
in,
and then analyse the returned responses to achieve what I want -
takes
the "ideal" 1 line call to about 7 or 8 at least - was trying to
encapsulate a call, but it might not be feasible.
Sounds like an argument for tuple return types:
(FirstNameProperty,­ LastNameProperty) = SplitName(FullName)­;
:)­
(Can you tell I've been learning Erlang? ;)
I've no idea how much work is required either in terms of language
design or CLR modifications to support this - I suspect it would be
feasible in "language only" but a lot more elegant with CLR
integration.
Jon
===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com
View archives and manage your subscription(s) at
===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com
View archives and manage your subscription(s) at
http://discuss.deve­lop.com

-- Barry

--
http://barrkel.blog­spot.com/

===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com

View archives and manage your subscription(s) at
http://discuss.deve­lop.com

===================­================
This list is hosted by DevelopMentor. http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

===================­================
This list is hosted by DevelopMentor http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Dean Cleaver 10 March 2008 14:12:33 permanent link ]
 Could cut the 10 lines down to about 7, but still won't change the fact
that it's not a one line function call. Particularly because the two
properties I need changed are interlinked - myobject.Property and
myObject.PropertyIs­Null. And it returns a Boolean depending on whether
or not there was an error, which is independent of the above two
properties, but of course those properties are closely tied.

This is in a project of about 500,000 lines of code, so I don't want to
just use nullable properties as there is too much code to check over.

Dino

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Shawn
Wildermuth
Sent: Tuesday, 11 March 2008 00:06
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

I know its not terribly efficient, but couldn't you return a simple
struct
or anonymous type with the multiple pieces of information?

Thanks,

Shawn Wildermuth
http://adoguy.com
http://wildermuthco­nsulting.com
http://geekdinners.­com
Microsoft MVP (C#), MCSD.NET, Author and Speaker

The Silverlight Tour is coming to a city near you!

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Dean
Cleaver
Sent: Monday, March 10, 2008 7:00 AM
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

Heh - cool - but as this website is entirely C#, I can't see Erlang
being of use, but the concept is interesting :)­

Dino

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Barry
Kelly
Sent: Monday, 10 March 2008 23:58
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

Dean Cleaver <dean.cleaver@XCEPT­IONSOFTWARE.COM> wrote:

Problem is my variables are of differing types... not that I can tell
from your code snippet, but It seems they are expected to be the same
type?

Erlang is dynamically typed. However, more generally, tuples are
structurally typed, and each field can have a separate type - that's
what makes them different to arrays. In statically typed functional
languages, where tuples are common, the type of e.g. ("Barry", "Kelly")
would be (String, String).

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Jon
Skeet
Sent: Monday, 10 March 2008 22:56
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments
Dean Cleaver wrote:
Yeah - getting my head around it now. Sadly, it's not VB I wanted it
for.
Is a shame- looks like I will have to declare 2 variables, pass them
in,
and then analyse the returned responses to achieve what I want -
takes
the "ideal" 1 line call to about 7 or 8 at least - was trying to
encapsulate a call, but it might not be feasible.
Sounds like an argument for tuple return types:
(FirstNameProperty,­ LastNameProperty) = SplitName(FullName)­;
:)­
(Can you tell I've been learning Erlang? ;)
I've no idea how much work is required either in terms of language
design or CLR modifications to support this - I suspect it would be
feasible in "language only" but a lot more elegant with CLR
integration.
Jon
===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com
View archives and manage your subscription(s) at
===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com
View archives and manage your subscription(s) at
http://discuss.deve­lop.com

-- Barry

--
http://barrkel.blog­spot.com/

===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com

View archives and manage your subscription(s) at
http://discuss.deve­lop.com

===================­================
This list is hosted by DevelopMentor. http://www.develop.­com

View archives and manage your subscription(s) at
http://discuss.deve­lop.com

===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com

View archives and manage your subscription(s) at
http://discuss.deve­lop.com

===================­================
This list is hosted by DevelopMentor http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Richard Howells 10 March 2008 14:14:11 permanent link ]
 Can you use a generic interface?

interface IWhatever<T, U, V>
{
T MyProp1 { get; set; }
U MyProp2 { get; set; }
V MyProp3 { get; set; }
}

class Blah<T, U, V> : IWhatever<T, U, V>
{
#region IWhatever<T,U,V> Members

public T MyProp1
{
get
{
throw new NotImplementedExcep­tion();
}
set
{
throw new NotImplementedExcep­tion();
}
}

public U MyProp2
{
get
{
throw new NotImplementedExcep­tion();
}
set
{
throw new NotImplementedExcep­tion();
}
}

public V MyProp3
{
get
{
throw new NotImplementedExcep­tion();
}
set
{
throw new NotImplementedExcep­tion();
}
}

#endregion
}

class Program
{
static void Main(string[] args)
{
Blah<string, int, bool> SpecialBlahForStrin­gIntBool = new
Blah<string, int, bool>();

}
}
Cheers,

- Richard
richard@dynamisys.c­o.uk
www.dynamisys.co.uk­
(T) +44 (0) 1793 731225
(M) +44 (0) 773 297 1786

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Shawn
Wildermuth
Sent: 10 March 2008 11:06
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

I know its not terribly efficient, but couldn't you return a simple struct
or anonymous type with the multiple pieces of information?

Thanks,

Shawn Wildermuth
http://adoguy.com
http://wildermuthco­nsulting.com
http://geekdinners.­com
Microsoft MVP (C#), MCSD.NET, Author and Speaker

The Silverlight Tour is coming to a city near you!

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Dean Cleaver
Sent: Monday, March 10, 2008 7:00 AM
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

Heh - cool - but as this website is entirely C#, I can't see Erlang
being of use, but the concept is interesting :)­

Dino

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Barry
Kelly
Sent: Monday, 10 March 2008 23:58
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

Dean Cleaver <dean.cleaver@XCEPT­IONSOFTWARE.COM> wrote:

Problem is my variables are of differing types... not that I can tell
from your code snippet, but It seems they are expected to be the same
type?

Erlang is dynamically typed. However, more generally, tuples are
structurally typed, and each field can have a separate type - that's
what makes them different to arrays. In statically typed functional
languages, where tuples are common, the type of e.g. ("Barry", "Kelly")
would be (String, String).

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Jon
Skeet
Sent: Monday, 10 March 2008 22:56
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments
Dean Cleaver wrote:
Yeah - getting my head around it now. Sadly, it's not VB I wanted it
for.
Is a shame- looks like I will have to declare 2 variables, pass them
in,
and then analyse the returned responses to achieve what I want -
takes
the "ideal" 1 line call to about 7 or 8 at least - was trying to
encapsulate a call, but it might not be feasible.
Sounds like an argument for tuple return types:
(FirstNameProperty,­ LastNameProperty) = SplitName(FullName)­;
:)­
(Can you tell I've been learning Erlang? ;)
I've no idea how much work is required either in terms of language
design or CLR modifications to support this - I suspect it would be
feasible in "language only" but a lot more elegant with CLR
integration.
Jon
===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com
View archives and manage your subscription(s) at
===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com
View archives and manage your subscription(s) at
http://discuss.deve­lop.com

-- Barry

--
http://barrkel.blog­spot.com/

===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com

View archives and manage your subscription(s) at
http://discuss.deve­lop.com

===================­================
This list is hosted by DevelopMentor. http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

===================­================
This list is hosted by DevelopMentor. http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

No virus found in this incoming message.
Checked by AVG.
Version: 7.5.518 / Virus Database: 269.21.7/1322 - Release Date: 09/03/2008
12:17


No virus found in this outgoing message.
Checked by AVG.
Version: 7.5.518 / Virus Database: 269.21.7/1322 - Release Date: 09/03/2008
12:17

===================­================
This list is hosted by DevelopMentor® http://www.develop.­com

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Dean Cleaver 10 March 2008 14:59:52 permanent link ]
 Can you apply a generic 10 times to the same class to apply to 10
different property pairs?

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Richard
Howells
Sent: Tuesday, 11 March 2008 00:14
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

Can you use a generic interface?

interface IWhatever<T, U, V>
{
T MyProp1 { get; set; }
U MyProp2 { get; set; }
V MyProp3 { get; set; }
}

class Blah<T, U, V> : IWhatever<T, U, V>
{
#region IWhatever<T,U,V> Members

public T MyProp1
{
get
{
throw new NotImplementedExcep­tion();
}
set
{
throw new NotImplementedExcep­tion();
}
}

public U MyProp2
{
get
{
throw new NotImplementedExcep­tion();
}
set
{
throw new NotImplementedExcep­tion();
}
}

public V MyProp3
{
get
{
throw new NotImplementedExcep­tion();
}
set
{
throw new NotImplementedExcep­tion();
}
}

#endregion
}

class Program
{
static void Main(string[] args)
{
Blah<string, int, bool> SpecialBlahForStrin­gIntBool = new
Blah<string, int, bool>();

}
}
Cheers,

- Richard
richard@dynamisys.c­o.uk
www.dynamisys.co.uk­
(T) +44 (0) 1793 731225
(M) +44 (0) 773 297 1786

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Shawn
Wildermuth
Sent: 10 March 2008 11:06
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

I know its not terribly efficient, but couldn't you return a simple
struct
or anonymous type with the multiple pieces of information?

Thanks,

Shawn Wildermuth
http://adoguy.com
http://wildermuthco­nsulting.com
http://geekdinners.­com
Microsoft MVP (C#), MCSD.NET, Author and Speaker

The Silverlight Tour is coming to a city near you!

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Dean
Cleaver
Sent: Monday, March 10, 2008 7:00 AM
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

Heh - cool - but as this website is entirely C#, I can't see Erlang
being of use, but the concept is interesting :)­

Dino

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Barry
Kelly
Sent: Monday, 10 March 2008 23:58
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments

Dean Cleaver <dean.cleaver@XCEPT­IONSOFTWARE.COM> wrote:

Problem is my variables are of differing types... not that I can tell
from your code snippet, but It seems they are expected to be the same
type?

Erlang is dynamically typed. However, more generally, tuples are
structurally typed, and each field can have a separate type - that's
what makes them different to arrays. In statically typed functional
languages, where tuples are common, the type of e.g. ("Barry", "Kelly")
would be (String, String).

-----Original Message-----
From: Discussion of development on the .NET platform using any managed
language [mailto:D­OTNET-CLR@DISCUSS.DEVELOP.COM] On Behalf Of Jon
Skeet
Sent: Monday, 10 March 2008 22:56
To: DOTNET-CLR@DISCUSS.­DEVELOP.COM
Subject: Re: [DOTNET-CLR] Why properties cannot be used as ref or out
arguments
Dean Cleaver wrote:
Yeah - getting my head around it now. Sadly, it's not VB I wanted it
for.
Is a shame- looks like I will have to declare 2 variables, pass them
in,
and then analyse the returned responses to achieve what I want -
takes
the "ideal" 1 line call to about 7 or 8 at least - was trying to
encapsulate a call, but it might not be feasible.
Sounds like an argument for tuple return types:
(FirstNameProperty,­ LastNameProperty) = SplitName(FullName)­;
:)­
(Can you tell I've been learning Erlang? ;)
I've no idea how much work is required either in terms of language
design or CLR modifications to support this - I suspect it would be
feasible in "language only" but a lot more elegant with CLR
integration.
Jon
===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com
View archives and manage your subscription(s) at
===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com
View archives and manage your subscription(s) at
http://discuss.deve­lop.com

-- Barry

--
http://barrkel.blog­spot.com/

===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com

View archives and manage your subscription(s) at
http://discuss.deve­lop.com

===================­================
This list is hosted by DevelopMentor. http://www.develop.­com

View archives and manage your subscription(s) at
http://discuss.deve­lop.com

===================­================
This list is hosted by DevelopMentor. http://www.develop.­com

View archives and manage your subscription(s) at
http://discuss.deve­lop.com

No virus found in this incoming message.
Checked by AVG.
Version: 7.5.518 / Virus Database: 269.21.7/1322 - Release Date:
09/03/2008
12:17


No virus found in this outgoing message.
Checked by AVG.
Version: 7.5.518 / Virus Database: 269.21.7/1322 - Release Date:
09/03/2008
12:17

===================­================
This list is hosted by DevelopMentor(r) http://www.develop.­com

View archives and manage your subscription(s) at
http://discuss.deve­lop.com

===================­================
This list is hosted by DevelopMentor http://www.develop.­com