-3

Why this error is shown as "member names cannot be the same as enclosing type". Why SpriteAnimationManager is shown as error in this code? //ComplexSpriteSheetAnimationGame.cs

    public ComplexSpriteSheetAnimationGame()
            {
                float timer;
                float interval = 200;
                AnimationSet animationSet;
            }

    protected override void Initialize()
            {
             animationSet = SpriteAnimationManager.Read(@”Content\SpriteDescription.xml”);
             base.Initialize();
            }

    //SpriteAnimationManager.cs
    public static int AnimationCount;
                // Read the Sprite Sheet Description information from the
                // description xml file
                public static AnimationSet Read(string Filename)
                {
                    AnimationSet animationSet = new AnimationSet();
                    // Create an XML reader for the sprite sheet animation
                    // description file
                    using (System.Xml.XmlReader reader =
                    System.Xml.XmlReader.Create(Filename))
                    {
                        // Create an XMLSerializer for the AnimationSet
                        XmlSerializer serializer = new
                        XmlSerializer(typeof(AnimationSet));
                        // Deserialize the Animation Set from the
                        // XmlReader to the animation set object
                        animationSet =
                        (AnimationSet)serializer.Deserialize(reader);
                    }
                    // Count the animations to Animation Count
                    AnimationCount = animationSet.Animations.Length;
                    return animationSet;
                }

enter image description here

madhu kumar
  • 786
  • 1
  • 12
  • 46
  • 1
    You have 16 errors. Start at the top. That error is exactly what it says but it could be caused by a syntax error above. – paparazzo Apr 10 '13 at 14:12
  • It says your error is on line 90. So why don't you show us what's on line 90? Tools->Option->Text Editor->C#->General->Display Line numbers checkbox – Steve H Apr 10 '13 at 14:54

2 Answers2

4

Apparently you're trying to declare a thing called SpriteAnimationManager inside something else that's also called SpriteAnimationManager. You can't do that; as it says in the error message, the names of a type's members can't be the same as the type itself (because it conflicts with the constructor, I think).

anaximander
  • 7,083
  • 3
  • 44
  • 62
  • thank u anaximander. i corrected the error and can u pls help me in correcting the error mentioned above. – madhu kumar Apr 12 '13 at 11:28
  • 1
    I'd recommend you start from error 1. Often that causes at least some of the others. Also, one class per file, and one problem per StackOverflow question. If my answer fixed the problem you asked about, then mark it as the answer. If you have another problem, post another question - don't edit your question to ask an entirely new question. – anaximander Apr 12 '13 at 14:32
1

A few new programming rules that will make your life simpler;

1: One class goes in One file. (class-to-file-ratio should be 1)
2: This also applies to interfaces/enums/etc
3: Start debugging the first error in your error-list.
4: Break these rules ONLY when you REALLY know why you do so.

Other than that, your problem is most likely cased by having a nested class (in your case I suspect you have an other declaration of the class "SpriteAnimationManager" which the highlighted declaration is within. Maybe you have accidently copied the declaration into the class itself, IDK...