Re: OOP question - multiple value properties
From: Nicholas Paldino [.NET/C# MVP] (mvp_at_spam.guard.caspershouse.com)
Date: 11/18/04
- Previous message: Visual Systems AB \(Martin Arvidsson\): "Q: Newbee question, regarding a couple of syntaxes in c#"
- In reply to: NOSPAM: "Re: OOP question - multiple value properties"
- Next in thread: Nicholas Paldino [.NET/C# MVP]: "Re: OOP question - multiple value properties"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 18 Nov 2004 16:31:04 -0500
With 2.0, you could create a generic type, which you would use to expose
the value as that type. Other than that, the only options you have now are
to expose it as an object (and force a cast), or create distinct types.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
"NOSPAM" <nospam@xsagfgsagsafg.com> wrote in message
news:FO-dnWmPJfGJkwDcRVn-1Q@rogers.com...
>
> Thanks.. what about other non-string value? such as DateTime, int? any
> suggestions?
>
>
>
> "Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
> wrote
> in message news:ezBJmgazEHA.576@TK2MSFTNGP14.phx.gbl...
>> Hi,
>>
>> That will not compile, try something like this instead:
>>
>> public struct Field
>> {
>> string Value;
>> string Description;
>> bool isUsed;
>> }
>> public class Person
>> {
>> Field _firstname;
>> public Field FirstName{ get; set ; }
>> }
>>
>> then you can do:
>> Person p = new Person();
>> p.FirstName.Value = "John Smith";
>> p.FirstName.Description = "First Name Text";
>> p.FirstName.IsUsed = true;
>>
>>
>>
>> Cheers,
>>
>> --
>> Ignacio Machin,
>> ignacio.machin AT dot.state.fl.us
>> Florida Department Of Transportation
>>
>>
>>
>> "NOSPAM" <nospam@xsagfgsagsafg.com> wrote in message
>> news:ss2dnb3m8dJhZwHcRVn-3w@rogers.com...
>> >I want to write a class that has multiple values associate to it
>> >
>> > public class Person {
>> > public string FirstName {get; set;}
>> > public string LastName {get; set;}
>> > public DateTime Date {get; set;}
>> > }
>> >
>> > For example, I want to create an object like this:
>> >
>> > Person p = new Person();
>> > p.FirstName = "John Smith";
>> > p.FirstName.Description = "First Name Text";
>> > p.FirstName.IsUsed = true;
>> >
>> > How do I write it? do I need to write a wrapper class for "string" and
>> > "DateTime"?
>> >
>> >
>> >
>> >
>> >
>> >
>>
>>
>
>
- Previous message: Visual Systems AB \(Martin Arvidsson\): "Q: Newbee question, regarding a couple of syntaxes in c#"
- In reply to: NOSPAM: "Re: OOP question - multiple value properties"
- Next in thread: Nicholas Paldino [.NET/C# MVP]: "Re: OOP question - multiple value properties"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|