Creating new class using switch statement.

  • Thread starter Thread starter CSharper
  • Start date Start date
C

CSharper

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,
 
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) :)
 
CSharper said:
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...
 
[...]
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top