SV: Creating structs
- From: "K Viltersten" <tmp1@xxxxxxxxxxxxxx>
- Date: Thu, 20 Mar 2008 21:52:24 +0100
I wish to send in a struct called Str
as a parameter to a method. Do i have
to create it first and then send it in or is it possible to create in upon construction?
I recommend that your first effort should always be to "just try it". :)
For a class i'd do this.
doSomething (new MyClass (1));
How can i do this for a struct?
Just as you do for a class. You can use "new" to "instantiate" the needed value for the struct to pass to the method. Just as with the example above, you'll only have access to that value from within the method unless the method copies the value somewhere else. But as long as that's okay, there's no problem (in fact, unlike with a class, you'd have to pass by reference for any changes within the method to be visible outside the method anyway, so if anything it's less likely to be a problem to pass a struct like that)
I'd like to send in an instance of the struct and pass in a
value to a constructor. However, constructors are not
allowed for structs.
As far i see i can't do the following.
doSomething (new MyStruct (1));
My compiler complains.
--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy
.
- Follow-Ups:
- Re: SV: Creating structs
- From: Peter Duniho
- Re: SV: Creating structs
- References:
- Creating structs
- From: K Viltersten
- Re: Creating structs
- From: Peter Duniho
- Creating structs
- Prev by Date: Re: SV: Creating structs
- Next by Date: Re: Creating a User Control
- Previous by thread: Re: Creating structs
- Next by thread: Re: SV: Creating structs
- Index(es):
Relevant Pages
|