Click here to Skip to main content
15,913,910 members
Home / Discussions / C#
   

C#

 
Questionfixed scope Pin
Chesnokov Yuriy1-Jul-10 0:46
professionalChesnokov Yuriy1-Jul-10 0:46 
AnswerRe: fixed scope Pin
Luc Pattyn1-Jul-10 0:55
sitebuilderLuc Pattyn1-Jul-10 0:55 
GeneralRe: fixed scope Pin
Chesnokov Yuriy1-Jul-10 7:56
professionalChesnokov Yuriy1-Jul-10 7:56 
GeneralRe: fixed scope Pin
Luc Pattyn1-Jul-10 9:28
sitebuilderLuc Pattyn1-Jul-10 9:28 
QuestionHow to use HashSet Pin
raju_shiva1-Jul-10 0:14
raju_shiva1-Jul-10 0:14 
AnswerRe: How to use HashSet Pin
Gonzalo Cao1-Jul-10 0:19
Gonzalo Cao1-Jul-10 0:19 
AnswerRe: How to use HashSet Pin
Luc Pattyn1-Jul-10 0:53
sitebuilderLuc Pattyn1-Jul-10 0:53 
GeneralRe: How to use HashSet Pin
raju_shiva1-Jul-10 1:48
raju_shiva1-Jul-10 1:48 
AnswerRe: How to use HashSet Pin
Laxman Auti1-Jul-10 1:12
Laxman Auti1-Jul-10 1:12 
AnswerRe: How to use HashSet Pin
Daniel Grunwald2-Jul-10 0:31
Daniel Grunwald2-Jul-10 0:31 
QuestionUser control Name Pin
chrisclarke1130-Jun-10 23:35
chrisclarke1130-Jun-10 23:35 
AnswerRe: User control Name Pin
freakyit30-Jun-10 23:44
freakyit30-Jun-10 23:44 
GeneralRe: User control Name Pin
chrisclarke111-Jul-10 0:10
chrisclarke111-Jul-10 0:10 
AnswerRe: User control Name Pin
OriginalGriff1-Jul-10 0:42
mveOriginalGriff1-Jul-10 0:42 
GeneralRe: User control Name Pin
chrisclarke111-Jul-10 2:05
chrisclarke111-Jul-10 2:05 
GeneralRe: User control Name Pin
OriginalGriff1-Jul-10 2:11
mveOriginalGriff1-Jul-10 2:11 
GeneralRe: User control Name Pin
freakyit1-Jul-10 2:05
freakyit1-Jul-10 2:05 
AnswerRe: User control Name Pin
freakyit1-Jul-10 2:27
freakyit1-Jul-10 2:27 
GeneralRe: User control Name Pin
chrisclarke111-Jul-10 7:40
chrisclarke111-Jul-10 7:40 
GeneralRe: User control Name Pin
freakyit2-Jul-10 3:04
freakyit2-Jul-10 3:04 
Questionvirtual/abstract methods and properties Pin
Daley8330-Jun-10 23:27
Daley8330-Jun-10 23:27 
AnswerRe: virtual/abstract methods and properties Pin
Peace ON30-Jun-10 23:51
Peace ON30-Jun-10 23:51 
GeneralRe: virtual/abstract methods and properties Pin
Daley831-Jul-10 0:00
Daley831-Jul-10 0:00 
AnswerRe: virtual/abstract methods and properties Pin
Peace ON1-Jul-10 0:20
Peace ON1-Jul-10 0:20 
AnswerRe: virtual/abstract methods and properties Pin
Łukasz Nowakowski1-Jul-10 0:22
Łukasz Nowakowski1-Jul-10 0:22 
If you really don't want to write ifs for each new fruit you add, you can use reflection like this:

<br />
Assembly assembly = typeof(FruitBase).Assembly;<br />
Type type = assembly.GetType(name);<br />
object obj = Activator.CreateInstance(type);<br />


This code assumes that all fruit classes are defined in the same assembly as FruitBase. After this code is executed obj contains fruit selected.
You should of course add some error checking, try-catches, but the basic idea remains.
Don't forget to rate answer, that helped you. It will allow other people find their answers faster.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.