Re: OOP question - multiple value properties

From: Nicholas Paldino [.NET/C# MVP] (mvp_at_spam.guard.caspershouse.com)
Date: 11/18/04

  • Next message: Peter Jausovec: "Re: Newbee question, regarding a couple of syntaxes in c#"
    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"?
    >> >
    >> >
    >> >
    >> >
    >> >
    >> >
    >>
    >>
    >
    > 
    

  • Next message: Peter Jausovec: "Re: Newbee question, regarding a couple of syntaxes in c#"

    Relevant Pages

    • Re: Asp call java class file.
      ... Not an expert but how do you expose the class to the ASP environment? ... > public class clsMail(){ ... public void sendMail(String subject, String Content, String ...
      (microsoft.public.inetserver.asp.general)
    • Re: XmlSerializer Collection with Collections
      ... > - a bunch of Option objects are contained within an OptionList ... > It is the extra level of object containment in the original version that ... >> public class TestSerializer ... >> public Question(string QuestionText, string Type, int Score, bool ...
      (microsoft.public.dotnet.xml)
    • Re: How to OPEN native PRINTER DIALOG -- Please HELP !!
      ... > function IsNetworkPrinter(PrinterName as string) as boolean ... Public Class YourPrintDialog ... Dim infos As New ArrayList ... ByRef cchBuffer As Int32) As Int32 ...
      (microsoft.public.dotnet.languages.vb)
    • Re: constructors/static methods and inheritance query
      ... public class BaseLine: IBaseLine { ... public static BaseLine Initialize(string x1, string y1, string ... public int keyLength; ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: Error : Complex DataBinding accepts as a data source either an IList or an IListSource
      ... > Public Class responseHistoricalData ... > Public equipmentID As String ... > Public proximity() As proximity ... > Private _serviceMeterHours As String ...
      (microsoft.public.dotnet.framework.webservices)