Click here to Skip to main content
15,905,874 members
Home / Discussions / C#
   

C#

 
QuestionRegular Expression pattern Pin
NarVish16-Dec-10 23:56
NarVish16-Dec-10 23:56 
AnswerRe: Regular Expression pattern Pin
Hiren solanki17-Dec-10 0:14
Hiren solanki17-Dec-10 0:14 
GeneralRe: Regular Expression pattern Pin
NarVish17-Dec-10 0:31
NarVish17-Dec-10 0:31 
AnswerRe: Regular Expression pattern Pin
Hiren solanki17-Dec-10 0:37
Hiren solanki17-Dec-10 0:37 
AnswerRe: Regular Expression pattern Pin
Ravi Sant17-Dec-10 0:20
Ravi Sant17-Dec-10 0:20 
GeneralRe: Regular Expression pattern Pin
Hiren solanki17-Dec-10 0:22
Hiren solanki17-Dec-10 0:22 
GeneralRe: Regular Expression pattern Pin
NarVish17-Dec-10 0:37
NarVish17-Dec-10 0:37 
GeneralRe: Regular Expression pattern Pin
Hiren solanki17-Dec-10 0:43
Hiren solanki17-Dec-10 0:43 
GeneralRe: Regular Expression pattern Pin
NarVish17-Dec-10 0:32
NarVish17-Dec-10 0:32 
AnswerRe: Regular Expression pattern Pin
Pete O'Hanlon17-Dec-10 0:37
mvePete O'Hanlon17-Dec-10 0:37 
GeneralRe: Regular Expression pattern Pin
NarVish17-Dec-10 1:05
NarVish17-Dec-10 1:05 
GeneralRe: Regular Expression pattern Pin
Pete O'Hanlon17-Dec-10 2:31
mvePete O'Hanlon17-Dec-10 2:31 
QuestionVSTO Word add-in 2007 Range.Find from background thread or worker Pin
Dino Mulahusic16-Dec-10 22:44
professionalDino Mulahusic16-Dec-10 22:44 
QuestionImage Upload and Resize Pin
Sudipta K Paik16-Dec-10 21:59
Sudipta K Paik16-Dec-10 21:59 
AnswerRe: Image Upload and Resize Pin
OriginalGriff16-Dec-10 22:16
mveOriginalGriff16-Dec-10 22:16 
JokeRe: Image Upload and Resize [modified] Pin
_Erik_17-Dec-10 3:21
_Erik_17-Dec-10 3:21 
QuestionEnumeration as Indexer: Is C# not the strongly-typed? Pin
Paul Selormey16-Dec-10 20:07
Paul Selormey16-Dec-10 20:07 
Hello All,

I found the need to use enumeration as indexer to simplify coding and just realized, I created bugs all over.
The situation is like this...
C#
using System;
using System.Collections.ObjectModel;

namespace Demo
{
    class Program
    {
        public enum AFormatType
        {
            None  = 0,
            ItemA = 1,
            ItemB = 2,
            ItemC = 3,
            ItemD = 4,
        }

        public class AFormat
        {
            AFormatType _type;

            public AFormat(AFormatType type) { _type = type; }

            public AFormatType FormatType
            {
                get { return _type; }
            }
        }

        public class AFormatCollection : Collection<AFormat>
        {   
            public AFormat this[AFormatType type]
            {
                get
                {
                    for (int i = 0; i < this.Count; i++)
                    {
                        AFormat format = base[i];
                        if (format.FormatType == type)
                        {
                            return format;
                        }
                    }

                    return null;
                }
            }
        }

        static void Main(string[] args)
        {
            AFormatCollection collFormats = new AFormatCollection();
            collFormats.Add(new AFormat(AFormatType.ItemA));
            collFormats.Add(new AFormat(AFormatType.ItemB));
            collFormats.Add(new AFormat(AFormatType.ItemC));
            collFormats.Add(new AFormat(AFormatType.ItemD));

            // Why should this be null in a strongly-typed language?
            AFormat testFormat = collFormats[0];

        }
    }
}


I was surprised to find that the testFormat is null. Is the C# enum nothing better than the C++? If the compiler considers this to be another this[int index], why did this compile successfully?

Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.

modified on Saturday, December 18, 2010 1:24 AM

AnswerRe: Enumeration as Indexer: Is C# not the strongly-typed? Pin
harold aptroot16-Dec-10 21:58
harold aptroot16-Dec-10 21:58 
GeneralRe: Enumeration as Indexer: Is C# not the strongly-typed? Pin
Paul Selormey16-Dec-10 23:40
Paul Selormey16-Dec-10 23:40 
AnswerRe: Enumeration as Indexer: Is C# not the strongly-typed? Pin
Eddy Vluggen16-Dec-10 22:06
professionalEddy Vluggen16-Dec-10 22:06 
GeneralRe: Enumeration as Indexer: Is C# not the strongly-typed? [modified] Pin
Paul Selormey16-Dec-10 23:26
Paul Selormey16-Dec-10 23:26 
GeneralRe: Enumeration as Indexer: Is C# not the strongly-typed? Pin
Eddy Vluggen17-Dec-10 0:38
professionalEddy Vluggen17-Dec-10 0:38 
GeneralRe: Enumeration as Indexer: Is C# not the strongly-typed? Pin
Paul Selormey17-Dec-10 0:48
Paul Selormey17-Dec-10 0:48 
GeneralRe: Enumeration as Indexer: Is C# not the strongly-typed? Pin
harold aptroot17-Dec-10 1:13
harold aptroot17-Dec-10 1:13 
GeneralRe: Enumeration as Indexer: Is C# not the strongly-typed? Pin
Paul Selormey17-Dec-10 1:19
Paul Selormey17-Dec-10 1:19 

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.