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

C#

 
Generalstore datagridview items under a button [modified] Need help! Pin
Member 474292219-Aug-09 23:43
Member 474292219-Aug-09 23:43 
GeneralRe: store datagridview items under a button [modified] Need help! Pin
OriginalGriff20-Aug-09 1:40
mveOriginalGriff20-Aug-09 1:40 
GeneralRe: store datagridview items under a button [modified] Need help! Pin
Member 474292220-Aug-09 2:08
Member 474292220-Aug-09 2:08 
GeneralRe: store datagridview items under a button [modified] Need help! Pin
OriginalGriff20-Aug-09 9:16
mveOriginalGriff20-Aug-09 9:16 
GeneralRe: store datagridview items under a button [modified] Need help! Pin
Member 474292220-Aug-09 21:38
Member 474292220-Aug-09 21:38 
GeneralRe: store datagridview items under a button [modified] Need help! Pin
OriginalGriff20-Aug-09 21:52
mveOriginalGriff20-Aug-09 21:52 
GeneralRe: store datagridview items under a button [modified] Need help! Pin
Member 474292222-Aug-09 2:08
Member 474292222-Aug-09 2:08 
QuestionGeneric Question - Implementing IEnumerable Pin
Programm3r19-Aug-09 23:37
Programm3r19-Aug-09 23:37 
<Hi all,

i have the following generic classes that allow me to build up a command list. But I am struggling with the implementation of the IEnumerable GetEnumerator. I do not know how to implement it so that it returns the results?

Here is my code:
    class Command<K, T>
    {
        public K Key;
        public T Item;
        public Command<K, T> NextCmd;

        public Command()
        {
            Key = default(K);
            Item = default(T);
            NextCmd = null;
        }

        public Command(K key, T item, Command<K, T> nextNode)
        {
            Key = key;
            Item = item;
            NextCmd = nextNode;
        }
    }

    public class ServerCommand<K, T> : IEnumerable<T> where K : IComparable<K>
    {
        private Command<K, T> tempCmd;

        private T Find(K commandKey)
        {
            Command<K, T> current = this.tempCmd.NextCmd;
            while (current.NextCmd != null)
            {
                if (current.Key.CompareTo(commandKey) == 0)
                    break;
                else
                    current = current.NextCmd;
            }
            return current.Item;
        }

        public T this[K commandKey]
        {
            get { return this.Find(commandKey); }
        }

        public ServerCommand()
        {
            tempCmd = new Command<K, T>();
        }

        public void AddCommand(K commandKey, T commandItem)
        {
            Command<K, T> newCmd = new Command<K, T>(commandKey, commandItem, this.tempCmd.NextCmd);
            this.tempCmd.NextCmd = newCmd;
        }

        public IEnumerator<T> GetEnumerator()
        {
// ????
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }


Many thanks in advance.
Kind regards,


The only programmers that are better C# programmers, are those who look like this -> Green Alien | [Alien]



Smile | :) Programm3r

My Blog: ^_^

AnswerRe: Generic Question - Implementing IEnumerable Pin
N a v a n e e t h20-Aug-09 0:08
N a v a n e e t h20-Aug-09 0:08 
GeneralRe: Generic Question - Implementing IEnumerable Pin
Programm3r20-Aug-09 1:40
Programm3r20-Aug-09 1:40 
AnswerRe: Generic Question - Implementing IEnumerable Pin
Nicholas Butler20-Aug-09 0:10
sitebuilderNicholas Butler20-Aug-09 0:10 
GeneralRe: Generic Question - Implementing IEnumerable Pin
Programm3r20-Aug-09 2:06
Programm3r20-Aug-09 2:06 
QuestionWhy doesn´t work the Code? Pin
nhqlbaislwfiikqraqnm19-Aug-09 22:48
nhqlbaislwfiikqraqnm19-Aug-09 22:48 
AnswerRe: Why doesn´t work the Code? Pin
padmanabhan N19-Aug-09 22:59
padmanabhan N19-Aug-09 22:59 
GeneralRe: Why doesn´t work the Code? Pin
nhqlbaislwfiikqraqnm19-Aug-09 23:05
nhqlbaislwfiikqraqnm19-Aug-09 23:05 
GeneralRe: Why doesn´t work the Code? Pin
padmanabhan N19-Aug-09 23:15
padmanabhan N19-Aug-09 23:15 
AnswerRe: Why doesn´t work the Code? Pin
musefan19-Aug-09 23:09
musefan19-Aug-09 23:09 
AnswerRe: Why doesn´t work the Code? Pin
Keith Barrow19-Aug-09 23:10
professionalKeith Barrow19-Aug-09 23:10 
GeneralRe: Why doesn´t work the Code? Pin
nhqlbaislwfiikqraqnm20-Aug-09 0:02
nhqlbaislwfiikqraqnm20-Aug-09 0:02 
GeneralRe: Why doesn´t work the Code? Pin
Luc Pattyn20-Aug-09 0:37
sitebuilderLuc Pattyn20-Aug-09 0:37 
GeneralRe: Why doesn´t work the Code? Pin
Keith Barrow20-Aug-09 0:39
professionalKeith Barrow20-Aug-09 0:39 
GeneralRe: Why doesn´t work the Code? Pin
Pete O'Hanlon20-Aug-09 1:02
mvePete O'Hanlon20-Aug-09 1:02 
GeneralRe: Why doesn´t work the Code? [modified] Pin
nhqlbaislwfiikqraqnm20-Aug-09 9:04
nhqlbaislwfiikqraqnm20-Aug-09 9:04 
Questionwrite at a particular position in a text document Pin
firefeet19-Aug-09 22:36
firefeet19-Aug-09 22:36 
AnswerRe: write at a particular position in a text document Pin
musefan19-Aug-09 23:13
musefan19-Aug-09 23:13 

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.