Creating new class using switch statement.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CSharper

    Creating new class using switch statement.

    I have a hashtable which has key and value. If the key is set to 'a'
    then I need to create a class1 and if it has key 'b' then I need to
    create class2 etc. (There is no name relation between the key and
    class name), Right now I am using switch/case to do it. Is it possible
    to do the same in Linq?

    Thanks,
  • Peter Duniho

    #2
    Re: Creating new class using switch statement.

    On Mon, 29 Sep 2008 14:02:40 -0700, CSharper <csharper@gmx.c omwrote:
    I have a hashtable which has key and value. If the key is set to 'a'
    then I need to create a class1 and if it has key 'b' then I need to
    create class2 etc. (There is no name relation between the key and
    class name), Right now I am using switch/case to do it. Is it possible
    to do the same in Linq?
    Given how flexible LINQ is, especially in its ability to operate on
    collections using delegates, surely you could get LINQ involved somehow.

    But I think a more interesting question is _should_ you? What is it about
    LINQ that you feel will bring some advantage to this particular problem?

    Pete

    Comment

    • CSharper

      #3
      Re: Creating new class using switch statement.

      On Sep 29, 4:38 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
      wrote:
      On Mon, 29 Sep 2008 14:02:40 -0700, CSharper <cshar...@gmx.c omwrote:
      I have a hashtable which has key and value. If the key is set to 'a'
      then I need to create a class1 and if it has key 'b' then I need to
      create class2 etc. (There is no name relation between the key and
      class name), Right now I am using switch/case to do it. Is it possible
      to do the same in Linq?
      >
      Given how flexible LINQ is, especially in its ability to operate on  
      collections using delegates, surely you could get LINQ involved somehow.
      >
      But I think a more interesting question is _should_ you?  What is it about  
      LINQ that you feel will bring some advantage to this particular problem?
      >
      Pete
      Good question. yes, Linq may not give anything, but I am trying to see
      how smart people who know Linq think to solve this problem. (so I can
      learn the tricks) :)

      Comment

      • Peter Duniho

        #4
        Re: Creating new class using switch statement.

        On Mon, 29 Sep 2008 14:54:54 -0700, CSharper <csharper@gmx.c omwrote:
        [...]
        >But I think a more interesting question is _should_ you?  What is it
        >about  
        >LINQ that you feel will bring some advantage to this particular problem?
        >
        Good question. yes, Linq may not give anything, but I am trying to see
        how smart people who know Linq think to solve this problem. (so I can
        learn the tricks) :)
        But, if all the smart people who know LINQ think the right way to solve
        this problem is to not use LINQ, then what? :)

        Pete

        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: Creating new class using switch statement.

          CSharper <csharper@gmx.c omwrote:
          Given how flexible LINQ is, especially in its ability to operate on  
          collections using delegates, surely you could get LINQ involved somehow..

          But I think a more interesting question is _should_ you?  What is it about  
          LINQ that you feel will bring some advantage to this particular problem?
          Good question. yes, Linq may not give anything, but I am trying to see
          how smart people who know Linq think to solve this problem. (so I can
          learn the tricks) :)
          Marc Gravell has some interesting tricks up his sleeves with a dynamic
          and flexible switch/case which works (in some cases anyway) even with
          LINQ to SQL. I don't know whether there's a public version or not
          though...

          --
          Jon Skeet - <skeet@pobox.co m>
          Web site: http://www.pobox.com/~skeet
          Blog: http://www.msmvps.com/jon.skeet
          C# in Depth: http://csharpindepth.com

          Comment

          • CSharper

            #6
            Re: Creating new class using switch statement.

            On Sep 29, 5:01 pm, "Peter Duniho" <NpOeStPe...@nn owslpianmk.com>
            wrote:
            On Mon, 29 Sep 2008 14:54:54 -0700, CSharper <cshar...@gmx.c omwrote:
            [...]
            But I think a more interesting question is _should_ you?  What is it 
            about  
            LINQ that you feel will bring some advantage to this particular problem?
            >
            Good question. yes, Linq may not give anything, but I am trying to see
            how smart people who know Linq think to solve this problem. (so I can
            learn the tricks) :)
            >
            But, if all the smart people who know LINQ think the right way to solve  
            this problem is to not use LINQ, then what?  :)
            >
            Pete
            I agree with the right way,but curious to know if there is
            alternative. It doesn't mean I am going to implement. But I was trying
            to think out side the box to se if there is a solution exist in LINQ
            at all. I am trying to see everything LINQ for me to learn LINQ that
            doesn't mean I am going to implement them :) It is a way of me forcing
            myself to learn this incredible LINQ.

            Comment

            Working...