Implicit conversion of arrays

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • The Last Danish Pastry

    Implicit conversion of arrays

    If I have two types, t1 and t2, say, I can write an implicit
    conversion operator from t1 to t2.

    Can I write implicit conversion operator from t1[] to t2[]?

    I don't think I can... but, if not, what is the "next nicest thing"?

    --
    Clive Tooth



  • The Last Danish Pastry

    #2
    Re: Implicit conversion of arrays

    "The Last Danish Pastry" <clivet@gmail.c omwrote in message
    news:69vq9dF34r k88U1@mid.indiv idual.net...
    If I have two types, t1 and t2, say, I can write an implicit
    conversion operator from t1 to t2.
    >
    Can I write implicit conversion operator from t1[] to t2[]?
    >
    I don't think I can... but, if not, what is the "next nicest thing"?
    I should have mentioned that I am talking about C#.

    --
    Clive Tooth



    Comment

    • =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=

      #3
      Re: Implicit conversion of arrays

      The Last Danish Pastry wrote:
      "The Last Danish Pastry" <clivet@gmail.c omwrote in message
      news:69vq9dF34r k88U1@mid.indiv idual.net...
      >
      >If I have two types, t1 and t2, say, I can write an implicit
      >conversion operator from t1 to t2.
      >>
      >Can I write implicit conversion operator from t1[] to t2[]?
      >>
      >I don't think I can... but, if not, what is the "next nicest thing"?
      >
      I should have mentioned that I am talking about C#.
      >
      If you're using .NET 3.5, you could write an extension method.

      If not, then you'll have to just write a static method somewhere.

      --
      Lasse Vågsæther Karlsen
      mailto:lasse@vk arlsen.no
      Blogger ist ein Veröffentlichungs-Tool von Google, mit dem du ganz einfach deine Gedanken der Welt mitteilen kannst. Mit Blogger kannst du problemlos Texte, Fotos und Videos in deinem persönlichen Blog oder deinem Team-Blog veröffentlichen.

      PGP KeyID: 0xBCDEA2E3

      Comment

      • Barry Kelly

        #4
        Re: Implicit conversion of arrays

        The Last Danish Pastry wrote:
        If I have two types, t1 and t2, say, I can write an implicit
        conversion operator from t1 to t2.
        >
        Can I write implicit conversion operator from t1[] to t2[]?
        >
        I don't think I can... but, if not, what is the "next nicest thing"?
        What are you using the arrays for?

        Would it make sense to wrap them in a (perhaps generic) class or struct
        with an indexing operator ('this' property)? You can add implicit
        conversions to classes and structs.

        -- Barry

        --

        Comment

        • Peter Duniho

          #5
          Re: Implicit conversion of arrays

          On Mon, 26 May 2008 06:45:12 -0700, Lasse Vågsæther Karlsen
          <lasse@vkarlsen .nowrote:
          >>[...]
          >>Can I write implicit conversion operator from t1[] to t2[]?
          >>>
          >>I don't think I can... but, if not, what is the "next nicest thing"?
          > I should have mentioned that I am talking about C#.
          >
          If you're using .NET 3.5, you could write an extension method.
          And if the requirement is somewhat "looser", and you don't really need an
          array per se as the output, but rather just something you can enumerate,
          you could even use the LINQ Cast<Tmethod.

          But as Lasse said, no implicit conversions.

          Pete

          Comment

          Working...