部件名称不能与它们的封闭类型的C# [英] member names cannot be the same as their enclosing type C#

查看:123
本文介绍了部件名称不能与它们的封闭类型的C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码是在C#和我使用Visual Studio 2010中

The code below is in C# and I'm using Visual Studio 2010.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace FrontEnd
{
    class Flow
    {
        long i;
        private int x,y;
        public int X
        {
            get;set;
        }
        public int Y
        {
            get;set;
        }

        private void Flow()
        {
            X = x;
            Y = y;
        }

        public void NaturalNumbers(int x, int y)
        {
            for (i = 0; i < 9999; i++)
            {
                Console.WriteLine(i);
            }
            MessageBox.Show("done");
        }
    }
}

当我编译上面的代码我得到这个错误:

When I compile the above code I get this error:

错误:流:成员名称不能与它们的封闭类型

Error: 'Flow': member names cannot be the same as their enclosing type

为什么呢?我怎样才能解决这个问题?

Why? How can I resolve this?

推荐答案

方法名称,这是类似的类名被称为构造函数。构造函数没有一个返回类型。所以,正确的,因为:

Method names which are similar to class name are called constructors. Constructors dont have a return type. So correct as:

private Flow()
{
   X = x;
   Y = y;
}

或重命名功能:

private void DoFlow()
{
   X = x;
   Y = y;
}



虽然整个代码没有任何意义,我。

Though the whole code does not make any sense to me.

这篇关于部件名称不能与它们的封闭类型的C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆