Click here to Skip to main content
15,891,864 members
Home / Discussions / C#
   

C#

 
AnswerRe: virtual/abstract methods and properties Pin
Łukasz Nowakowski1-Jul-10 0:22
Łukasz Nowakowski1-Jul-10 0:22 
GeneralRe: virtual/abstract methods and properties Pin
Daley831-Jul-10 1:04
Daley831-Jul-10 1:04 
AnswerUPDATE: virtual/abstract methods and properties Pin
Daley831-Jul-10 1:02
Daley831-Jul-10 1:02 
GeneralRe: UPDATE: virtual/abstract methods and properties Pin
Łukasz Nowakowski1-Jul-10 1:29
Łukasz Nowakowski1-Jul-10 1:29 
GeneralRe: UPDATE: virtual/abstract methods and properties Pin
Daley831-Jul-10 1:45
Daley831-Jul-10 1:45 
GeneralRe: UPDATE: virtual/abstract methods and properties Pin
Łukasz Nowakowski1-Jul-10 1:54
Łukasz Nowakowski1-Jul-10 1:54 
GeneralRe: UPDATE: virtual/abstract methods and properties Pin
harold aptroot1-Jul-10 3:47
harold aptroot1-Jul-10 3:47 
AnswerRe: virtual/abstract methods and properties Pin
Ennis Ray Lynch, Jr.1-Jul-10 3:44
Ennis Ray Lynch, Jr.1-Jul-10 3:44 
Personally, I would caution against using reflection. It is poor practice when you own the code.

Now to get down to the Nitty gritty, will your fruit objects perform custom actions based on the object type? It is possible that you have one of the cases for less classes and not more. The pattern below works well when you have a database of objects that really only differ Categorically as far as you are concerned. Technically it can be considered a Domain. You see it a lot when loading lists from databases for drop downs. I included the enumerator and the static Get method for use in populating and retrieving from combo boxes however there are an infinite number of ways to do it.

Since this is for an interview, this method is nice in that it circumvents many of the expected problems and gotchas with a lot less code.

public class Fruit {
    private static Dictionary<string, Fruit> mFruits = new Dictionary<string, Fruit>();
    private string mName;
    private string mColor;

    public static Fruit GetFruit(string name){
        return mFruits[name];
    }
    public static IEnumerator<Fruit> GetFruits() {
        return mFruits.Values.GetEnumerator();
    }

    public string Name {
        get {
            return mName;
        }
        private set {
            mName = value;
        }
    }
    public string Color {
        get {
            return mColor;
        }
        private set {
            mColor = value;
        }
    }

    private Fruit(string name, string color) {
        Name = name;
        Color = color;
    }
    static Fruit() {
        mFruits.Add("Apple", new Fruit("Apple", "Red"));
        mFruits.Add("Banana", new Fruit("Banana", "Yellow"));
    }
}


Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting.

A man said to the universe:
"Sir I exist!"
"However," replied the universe,
"The fact has not created in me
A sense of obligation."
--Stephen Crane


QuestionHow to join 2 string[] objects Pin
Chesnokov Yuriy30-Jun-10 23:00
professionalChesnokov Yuriy30-Jun-10 23:00 
AnswerRe: How to join 2 string[] objects Pin
R. Giskard Reventlov30-Jun-10 23:03
R. Giskard Reventlov30-Jun-10 23:03 
AnswerRe: How to join 2 string[] objects Pin
freakyit30-Jun-10 23:19
freakyit30-Jun-10 23:19 
AnswerRe: How to join 2 string[] objects Pin
Ayman Kouzayha30-Jun-10 23:31
Ayman Kouzayha30-Jun-10 23:31 
AnswerRe: How to join 2 string[] objects Pin
Laxman Auti1-Jul-10 0:19
Laxman Auti1-Jul-10 0:19 
GeneralRe: How to join 2 string[] objects Pin
Chesnokov Yuriy1-Jul-10 0:41
professionalChesnokov Yuriy1-Jul-10 0:41 
AnswerRe: How to join 2 string[] objects Pin
Ravi Bhavnani2-Jul-10 4:58
professionalRavi Bhavnani2-Jul-10 4:58 
QuestionConvert 32-bit Bitmap file to 24-bit Pin
Ayman Kouzayha30-Jun-10 22:28
Ayman Kouzayha30-Jun-10 22:28 
QuestionRe: Convert 32-bit Bitmap file to 24-bit Pin
Ayman Kouzayha30-Jun-10 23:21
Ayman Kouzayha30-Jun-10 23:21 
QuestionOnShown event not always triggered Pin
Gonzalo Cao30-Jun-10 21:43
Gonzalo Cao30-Jun-10 21:43 
QuestionHow to Integrate Quick Book With VS08 Pin
kanchan112330-Jun-10 20:32
kanchan112330-Jun-10 20:32 
AnswerRe: How to Integrate Quick Book With VS08 Pin
Richard MacCutchan30-Jun-10 21:41
mveRichard MacCutchan30-Jun-10 21:41 
QuestionEWS attribute 'Value' missing.. ARGG Pin
Jacob Dixon30-Jun-10 9:47
Jacob Dixon30-Jun-10 9:47 
QuestionLABEL for X and Y Axis Pin
It_tech30-Jun-10 8:51
It_tech30-Jun-10 8:51 
AnswerRe: LABEL for X and Y Axis Pin
JF201530-Jun-10 18:11
JF201530-Jun-10 18:11 
GeneralRe: LABEL for X and Y Axis Pin
It_tech30-Jun-10 19:12
It_tech30-Jun-10 19:12 
GeneralRe: LABEL for X and Y Axis Pin
JF201530-Jun-10 19:23
JF201530-Jun-10 19:23 

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.