C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » .NET »

Error in Comment lines(/* */)


Posted Date: 31 Dec 2008      Posted By: murthy      Member Level: Bronze     Points: 1   Responses: 4





i wrote this below code in codebehind in dotnet(asp.net and C#).i get error in some lines what i put in comments(/* */) what is the mistake?

protected void readXML()
{
XDocument xmlDoc = XDocument.Load(Server.MapPath("Poll.xml"));

/* var votes = from vote in xmlDoc.Descendants("Vote");
select new
{
Name = vote.Element("Name").Value;
Vote = vote.Element("Choice").Value;
}
*/
int mCount;
int oCount;
mCount = 0;
oCount = 0;

foreach (var vote in votes)
{
if (vote.Vote == "McCain")
mCount++;
else if (vote.Vote == "Obama")
oCount++;
}

double theTotal;
theTotal = mCount + oCount;
double mPercent;
double oPercent;
mPercent = (mCount/theTotal)*100;
oPercent = (oCount/theTotal)*100;

litResults.Visible = true;
litResults.Text = "Obama: " + oCount + " votes (" + oPercent + "%).<br />";
litResults.Text = litResults.Text + "McCain: " + mCount + " votes (" + mPercent + "%).<br /><br />";
}





Responses

Author: chatanya agrawal    31 Dec 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 1

votes is not declared.
Also can you put the actual error message that you are getting?



Author: divya    31 Dec 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

Hi
its correct ,try like this also
// var votes = from vote in xmlDoc.Descendants("Vote");
//select new
//{
//Name = vote.Element("Name").Value;
//Vote = vote.Element("Choice").Value;
//}
//



Author: Babu Akkandi    31 Dec 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 2

Hi,

There is no error in your Comment.

Please Ensure the Followings,

1. Include the following Namespace in your Code

using System.Xml;
using System.Xml.Linq;

2.Declare the Variable "votes"


Hope it Helps!

Thanks and Regards,
Babu Akkandi
Microsoft Technology



Author: Chandra Mohan    31 Dec 2008Member Level: BronzeRating: 2 out of 52 out of 5     Points: 0

Looks like no errors. Is the code file saved? :)


Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Graphs in C#
Previous : Difference between skinfile,stylesheet
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use