Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

C# - Member Names Cannot be the Same as their Enclosing Type in Asp.net

Feb 20, 2015
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#.

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#.

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.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

0 comments :

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.