Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

member names cannot be the same as their enclosing type C#

Tags:

c#

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?

like image 848
SHRI Avatar asked Apr 09 '12 08:04

SHRI


1 Answers

Method names which are same as the class name are called constructors. Constructors do not have a return type. So correct as:

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

Or rename the function as:

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

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

like image 156
mshsayem Avatar answered Oct 13 '22 18:10

mshsayem