Click here to Skip to main content
15,879,683 members
Home / Discussions / C#
   

C#

 
GeneralRe: pdf printing Pin
amadeonMk30-Jan-04 8:02
amadeonMk30-Jan-04 8:02 
GeneralRe: pdf printing Pin
Heath Stewart30-Jan-04 9:39
protectorHeath Stewart30-Jan-04 9:39 
QuestionWhere should I start studying for Managed DirectX if I'm a n00b? Pin
C# n00b30-Jan-04 1:27
C# n00b30-Jan-04 1:27 
AnswerRe: Where should I start studying for Managed DirectX if I'm a n00b? Pin
Mazdak30-Jan-04 1:35
Mazdak30-Jan-04 1:35 
GeneralRe: Where should I start studying for Managed DirectX if I'm a n00b? Pin
C# n00b30-Jan-04 1:42
C# n00b30-Jan-04 1:42 
GeneralRe: Where should I start studying for Managed DirectX if I'm a n00b? Pin
Mazdak30-Jan-04 1:54
Mazdak30-Jan-04 1:54 
GeneralPrinting Problem Pin
cjengler30-Jan-04 1:13
cjengler30-Jan-04 1:13 
GeneralWell now I'm convinced Pin
Rob Manderson29-Jan-04 22:41
protectorRob Manderson29-Jan-04 22:41 
that the C# compiler does great diagnostics. (This is my first essay into C# enumerable classes so if I've missed something obvious be gentle with me.)

I've written a class like this.
C#
public class FilterEnumerator : IEnumerator
{
    #region IEnumerator Members

    private int index = -1;
    private ArrayList data;

    public FilterEnumerator(ArrayList Data)
    {
        foreach (String s in Data)
            data.Add(s);

        Reset();
    }

    public void Reset()
    {
        index = -1;
    }

    public object Current
    {
        get
        {
            if (index >= 0 && index < data.Count)
                return data[index];
            else
                return null;
        }
    }

    public bool MoveNext()
    {
        return (++index < data.Count);
    }

    #endregion

}

It compiles but the compiler throws a warning at me for the
C#
private ArrayList data;

member pointing out that this member variable is never assigned to and will always be null. It took a bit of headscratching until I realised that the compiler was noticing that I had never actually created something for data to refer to. What confused me (does this show I'm a c++ programmer learning a new language Smile | :) ?) was that I could quite clearly see that I had assigned to data in the constructor. Or so I thought.

The solution is of course to write the constructor thusly:
C#
public FilterEnumerator(ArrayList Data)
{
    data = new ArrayList;

    foreach (String s in Data)
        data.Add(s);

    Reset();
}


Well I say the solution is 'of course' but I'm still thinking in c++ terms. Is there a better solution?

And why am I convinced that the c# compiler does better diagnostics? I'm a firm believer in compiling at the maximum error level and converting warnings to errors. I want to know if the compiler thinks my code is questionable before I even start to debug it. But this error would have slipped past the c++ compiler.

Rob Manderson

Paul Watson wrote:What sense would you most dislike loosing?

Ian Darling replied.

Telepathy

Then I'd no longer be able to find out everyones dirty little secrets The Lounge, December 4 2003

GeneralRe: Well now I'm convinced Pin
Stephane Rodriguez.29-Jan-04 23:24
Stephane Rodriguez.29-Jan-04 23:24 
GeneralRe: Well now I'm convinced Pin
Brian Delahunty30-Jan-04 3:12
Brian Delahunty30-Jan-04 3:12 
GeneralRe: Well now I'm convinced Pin
Stephane Rodriguez.30-Jan-04 4:49
Stephane Rodriguez.30-Jan-04 4:49 
GeneralRe: Well now I'm convinced Pin
Brian Delahunty30-Jan-04 5:45
Brian Delahunty30-Jan-04 5:45 
GeneralRe: Well now I'm convinced Pin
Stephane Rodriguez.30-Jan-04 6:08
Stephane Rodriguez.30-Jan-04 6:08 
GeneralGDI+ problem (tough!) Pin
r929-Jan-04 22:38
r929-Jan-04 22:38 
GeneralRe: GDI+ problem (tough!) Pin
r929-Jan-04 22:39
r929-Jan-04 22:39 
GeneralRe: GDI+ problem (tough!) Pin
Shree30-Jan-04 0:44
Shree30-Jan-04 0:44 
GeneralRe: GDI+ problem (tough!) Pin
r930-Jan-04 1:56
r930-Jan-04 1:56 
Questioncontrolling the autoscroll behaviour of panel? Pin
misterbear29-Jan-04 21:49
misterbear29-Jan-04 21:49 
Answerwhat the ascii figure should look like... Pin
misterbear29-Jan-04 21:55
misterbear29-Jan-04 21:55 
GeneralRe: what the ascii figure should look like... Pin
Heath Stewart30-Jan-04 4:31
protectorHeath Stewart30-Jan-04 4:31 
GeneralRe: what the ascii figure should look like... Pin
misterbear31-Jan-04 11:30
misterbear31-Jan-04 11:30 
GeneralRegular Expression Pin
Member 33502229-Jan-04 20:36
Member 33502229-Jan-04 20:36 
GeneralRe: Regular Expression Pin
Kentamanos29-Jan-04 21:32
Kentamanos29-Jan-04 21:32 
GeneralRe: Regular Expression Pin
Heath Stewart30-Jan-04 4:03
protectorHeath Stewart30-Jan-04 4:03 
Generalprevent re-opening of application Pin
azusakt29-Jan-04 19:46
azusakt29-Jan-04 19:46 

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.