Wrox Programmer Forums
|
C# 4.0 aka C# 2010 General Discussion Discussions about the C# 4.0, C# 4, Visual C# 2010 language and tool not related to any specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 4.0 aka C# 2010 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 14th, 2012, 09:29 AM
Authorized User
 
Join Date: Sep 2012
Posts: 29
Thanks: 14
Thanked 0 Times in 0 Posts
Default array of difficulties

There is an array of difficulties in this program.

Code:
namespace scratchpad3
{
    class Program
    {
      public static void Main()
      {
        aclass ac = new aclass();
      // say I won’t return any method      
        }
    }

       public  class aclass :IEnumerable
    {
       int[] star = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

       public IEnumerator  GetEnumerator()
        {
  //*****************What will happen if I declare the enumerator here??????????
      

foreach (int i in star)
            {
                Console.WriteLine(i);
                Console.Read();
            }
        }
        

    }

 }
This program gives an ERROR message:-
Error 1 Using the generic type 'System.Collections.Generic.IEnumerable<T>' requires 1 type arguments C:\Users\lenovo\documents\visual studio 2010\Projects\scratchpad3\Program.cs 19 30 scratchpad3
But what if IF i WISH TO IMPLEMENT A NON-GENERIC TYPE:-
What I mean is that if i use IEnumerable instead of IEnumerable<T>
Even doing this i.e. putting IEnumerable<int> gives error message
ERROR
Error 1 'scratchpad3.aclass' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'scratchpad3.aclass.GetEnumerator()' cannot implement 'System.Collections.IEnumerable.GetEnumerator()' because it does not have the matching return type of 'System.Collections.IEnumerator'. C:\Users\lenovo\documents\visual studio 2010\Projects\scratchpad3\Program.cs 18 18 scratchpad3
 
Old September 16th, 2012, 12:54 PM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 171
Thanks: 0
Thanked 14 Times in 14 Posts
Default

hover your cursor over IEnumerable (up top where are inheriting it), you'll see a blue line appear under the word IEnumerable, hover over that, click it, then select "Implement..."
The Following User Says Thank You to mtranchi For This Useful Post:
amigo1 (October 1st, 2012)
 
Old October 1st, 2012, 09:43 AM
Authorized User
 
Join Date: Sep 2012
Posts: 29
Thanks: 14
Thanked 0 Times in 0 Posts
Default thanks

sorry for being late

thank you





Similar Threads
Thread Thread Starter Forum Replies Last Post
Difficulties getting WroxUnited and stuff set up Rusty0918 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 October 17th, 2007 11:14 PM
SELECT Query Difficulties mccoy Access 2 June 17th, 2007 06:02 PM
Access2003 Difficulties marclf Access VBA 0 October 31st, 2006 09:04 AM
Insert on server difficulties! fskilnik Dreamweaver (all versions) 4 August 22nd, 2005 10:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.