Introduction:
Here I will explain how to solve problem of “member names cannot be the same as their enclosing type” in asp.net using c#. Actually this “member names cannot be the same as their enclosing type” problem occurred while compiling the code it’s because of using same class name for method in asp.net using c#.
Here I will explain how to solve problem of “member names cannot be the same as their enclosing type” in asp.net using c#. Actually this “member names cannot be the same as their enclosing type” problem occurred while compiling the code it’s because of using same class name for method in asp.net using c#.
Description:
In previous post I explained iis cannot open w3svc service on computer’.’.access denied, cannot load file or assembly ‘file:///’ or one of its dependencies, Ajax error unable to get the value of property ‘UI’ object is null or undefined, could not load file or assembly or one of its dependencies and many more articles related to errors in asp.net using c#, vb.net. Now I will explain how how to solve problem of “member names cannot be the same as their enclosing type” in asp.net using c#.
In previous post I explained iis cannot open w3svc service on computer’.’.access denied, cannot load file or assembly ‘file:///’ or one of its dependencies, Ajax error unable to get the value of property ‘UI’ object is null or undefined, could not load file or assembly or one of its dependencies and many more articles related to errors in asp.net using c#, vb.net. Now I will explain how how to solve problem of “member names cannot be the same as their enclosing type” in asp.net using c#.
Actually this problem occurred
because of using same class name for method like as shown below
public partial class ConvertNumbertoWords : System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
}
public static string
ConvertNumbertoWords(int number)
{
if (number == 0)
return "ZERO";
if (number < 0)
return "minus " + ConvertNumbertoWords(Math.Abs(number));
}
}
|
If you observe above code I used same class name for method.
Actually whenever we declared method
name same as class name it will treat it as constructor generally constructors will not have any return types
because of that its throwing error like “member
names cannot be the same as their enclosing type”.
To solve this problem
you need to change method name like as shown below
public partial class ConvertNumbertoWords : System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
}
public static string NumbertoWords(int number)
{
if (number == 0)
return "ZERO";
if (number < 0)
return "minus " + ConvertNumbertoWords(Math.Abs(number));
}
}
|
I hope it helps you to solve your problem………
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
0 comments :
Note: Only a member of this blog may post a comment.