-3

为什么此错误显示为“成员名称不能与封闭类型相同”。为什么 SpriteAnimationManager 在此代码中显示为错误?//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;
                }

在此处输入图像描述

4

2 回答 2

4

显然,您正在尝试SpriteAnimationManager在其他称为SpriteAnimationManager. 你不能那样做;正如它在错误消息中所说,类型成员的名称不能与类型本身相同(因为它与构造函数冲突,我认为)。

于 2013-04-10T13:57:27.173 回答
1

一些新的编程规则,让你的生活更简单;

1:一个类进入一个文件。(class-to-file-ratio 应该是 1)
2:这也适用于 interfaces/enums/etc
3:开始调试错误列表中的第一个错误。
4:只有在你真正知道为什么要这样做时才打破这些规则。

除此之外,您的问题很可能是由嵌套类引起的(在您的情况下,我怀疑您有另一个类“SpriteAnimationManager”的声明,突出显示的声明在其中。也许您不小心将声明复制到了类本身中, 身份证...

于 2013-04-12T13:28:01.423 回答