Click here to Skip to main content
15,911,531 members
Home / Discussions / C#
   

C#

 
QuestionC# Pin
Nath1-Mar-08 0:15
Nath1-Mar-08 0:15 
GeneralRe: C# Pin
yogesh_kumar_agarwal1-Mar-08 0:28
yogesh_kumar_agarwal1-Mar-08 0:28 
GeneralRe: C# Pin
Luc Pattyn1-Mar-08 0:49
sitebuilderLuc Pattyn1-Mar-08 0:49 
JokeRe: C# Pin
Xmen Real 1-Mar-08 2:32
professional Xmen Real 1-Mar-08 2:32 
GeneralRead the forum guidelines Pin
pmarfleet1-Mar-08 2:32
pmarfleet1-Mar-08 2:32 
GeneralRe: Read the forum guidelines Pin
Not Active1-Mar-08 9:19
mentorNot Active1-Mar-08 9:19 
GeneralRe: C# Pin
Paul Conrad1-Mar-08 12:29
professionalPaul Conrad1-Mar-08 12:29 
GeneralImplementing IEnumerable<t></t> Pin
Jammer1-Mar-08 0:14
Jammer1-Mar-08 0:14 
Hi All,

I've been looking at this for a few hours now, tried a few things I've read on the web with not much luck and I'm a git lost, I've never done this before and I'm getting a bit confused by the examples I've read online to be honest. How do I implement IEnumerable<t> on this code:

class BuildGenericLists : IEnumerable<T>
{
    // this defines the structure of the main file table object that will
    // contain the list of files and information gained from the system scan.
    public struct Filelist
    {
        public string file_name, file_size, file_ext, last_access;

        // create a constructor
        public Filelist(string fileName, string fileSize, string fileExt, string lastAccess)
        {
            file_name = fileName;
            file_size = fileSize;
            file_ext = fileExt;
            last_access = lastAccess;
        }
    }

    // this function builds the main table from the structure defined above and returns an
    // empty generic list ready for populating.
    public static object BuildMainFileList()
    {
        List<filelist> MainFileTableObject = new List<filelist>();

        // just adding some test data to the table for testing purposes.
        MainFileTableObject.Add(new Filelist(@"G:\Jammer1\", "2132987KB", ".WAV", "12/12/2001"));
        MainFileTableObject.Add(new Filelist(@"G:\Jammer2\", "2132987KB", ".AIF", "12/12/2002"));
        MainFileTableObject.Add(new Filelist(@"G:\Jammer3\", "2132987KB", ".PRG", "12/12/2003"));
        MainFileTableObject.Add(new Filelist(@"G:\Jammer4\", "2132987KB", ".ASD", "12/12/2004"));
        MainFileTableObject.Add(new Filelist(@"G:\Jammer5\", "2132987KB", ".WAV", "12/12/2005"));
        MainFileTableObject.Add(new Filelist(@"G:\Jammer6\", "2132987KB", ".WAV", "12/12/2006"));

        // return the table
        return MainFileTableObject;
    }
}</filelist></filelist>


Should the

: IEnumerable<T>


actually be on the following line instead?

public static object BuildMainFileList();


Once this has been inherited how would the code for the GetEnumerator() / Current / Move Next be inserted into the code?

Sorry I know this is going back to basics for most of you but help a newbie Smile | :) The examples on the net all seem to differ and I can't work out what is needed and what isn't needed as there seems to be a difference between the generic implementation and other implementations.

TIA,

James.
GeneralRe: Implementing IEnumerable Pin
Not Active1-Mar-08 2:19
mentorNot Active1-Mar-08 2:19 
GeneralRe: Implementing IEnumerable Pin
Jammer1-Mar-08 2:28
Jammer1-Mar-08 2:28 
GeneralRe: Implementing IEnumerable Pin
Jammer1-Mar-08 3:01
Jammer1-Mar-08 3:01 
GeneralRe: Implementing IEnumerable Pin
papadimitriou1-Mar-08 3:51
papadimitriou1-Mar-08 3:51 
GeneralRe: Implementing IEnumerable Pin
Jammer1-Mar-08 4:01
Jammer1-Mar-08 4:01 
GeneralRe: Implementing IEnumerable Pin
Jammer1-Mar-08 4:05
Jammer1-Mar-08 4:05 
GeneralRe: Implementing IEnumerable Pin
papadimitriou1-Mar-08 4:16
papadimitriou1-Mar-08 4:16 
GeneralRe: Implementing IEnumerable Pin
Jammer1-Mar-08 4:23
Jammer1-Mar-08 4:23 
GeneralRe: Implementing IEnumerable Pin
Jammer1-Mar-08 5:27
Jammer1-Mar-08 5:27 
GeneralRe: Implementing IEnumerable Pin
Jammer1-Mar-08 8:35
Jammer1-Mar-08 8:35 
GeneralRe: Implementing IEnumerable Pin
buchstaben1-Mar-08 8:40
buchstaben1-Mar-08 8:40 
GeneralRe: Implementing IEnumerable Pin
Jammer1-Mar-08 8:50
Jammer1-Mar-08 8:50 
GeneralRe: Implementing IEnumerable Pin
buchstaben2-Mar-08 2:38
buchstaben2-Mar-08 2:38 
GeneralRe: Implementing IEnumerable Pin
Jammer2-Mar-08 2:55
Jammer2-Mar-08 2:55 
GeneralRe: Implementing IEnumerable Pin
buchstaben2-Mar-08 3:33
buchstaben2-Mar-08 3:33 
GeneralRe: Implementing IEnumerable Pin
Jammer2-Mar-08 3:46
Jammer2-Mar-08 3:46 
GeneralRe: Implementing IEnumerable Pin
Guffa1-Mar-08 8:52
Guffa1-Mar-08 8:52 

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.