【发布时间】:2010-10-01 05:58:10
【问题描述】:
我在这里有这个简单的 ASP.NET 页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Tree.aspx.cs" Inherits="CoconutTree.One" %>
<html>
<head>
<title>Planting Trees</title>
<script runat="server">
protected void Page_Load(Object Source, EventArgs E)
{
string msg = "Let's plant some trees!<br/>";
// Create a new Tree
Tree tree1 = new Tree();
msg += "I've created a tree with a height of " +
tree1.height + " metre(s).<br/>";
tree1.Grow(3);
msg += "After a bit of growth, it's now up to " +
tree1.height + " metre(s) tall.<br/>";
msg += "Maybe eventually it will grow to 10 meters tall!</br>…<br/>";
tree1.Grow(7);
msg += "*15 years later*<br/>Let's check out our tree's height now! It's now up to " + tree1.height + " meter(s) tall! Awesome!<br/>";
Output.Text = msg;
string msg2 = "Let's plant some coconut trees!<br/>";
// Create a new Tree
CoconutTree coconutTree1 = new CoconutTree();
msg2 += "I've created a tree with " + coconutTree1.numNuts + " coconuts.<br/>";
coconutTree1.GrowNut(10);
ms2 += "I've now grown " + coconutTree1.numNuts + " coconuts on our tree.<br/>";
Output2.Text = msg2;
}
</script>
</script>
</head>
<body>
<p><asp:label runat="server" id="Output" /></p>
<p><asp:label runat="server" id="Output2" /></p>
</body>
</html>
有了这个简单的类:
namespace One
{
public class Tree {
public int height = 0;
public void Grow(int heightToGrow) {
height += heightToGrow;
}
}
public class CoconutTree : Tree {
public int numNuts = 0; //Number of coconuts
public void GrowNut(int numberToGrow) {
numNuts += numberToGrow;
}
public void PickNut(int numberToPick) {
numNuts -= numberToPick;
}
}
}
更新更新:
解析器错误
描述:解析服务此请求所需的资源时出错。检查您的源文件并对其进行修改以修复此错误。
解析器错误消息:找不到类型 CoconutTree.One
【问题讨论】:
-
顺便说一句,您可以在一个文件中包含多个类,所以我认为这不是问题。
-
哇!我的错,对此感到抱歉。
标签: c# asp.net compiler-construction mono compilation