hvad gør jeg galt
Jeg har lavet følgende test metode, der modtager to tal og ligger dem sammen:dll-fil
------------------------------
using System;
using System.Text;
namespace sub {
public class subObj {
private int _tal1;
private int _tal2;
public int tal1 {
get {
return _tal1;
}
set {
_tal1 = value;
}
}
public int tal2 {
get {
return _tal2;
}
set {
_tal2 = value;
}
}
public int res() {
return _tal1 + _tal2;
}
}
}
aspx-fil
---------------------------------------------------
<%@ Import Namespace="sub" %>
<html>
<style>
div
{
font: 8pt verdana;
background-color:cccccc;
border-color:black;
border-width:1;
border-style:solid;
padding:10,10,10,10;
}
</style>
<script language="C#" runat="server">
public void Page_Load(Object sender, EventArgs E)
{
subObj comp = new subObj();
comp.tal1 = 2;
comp.tal2 = 5;
Message.InnerHtml = comp.res();
}
</script>
<body style="font: 10pt verdana">
<h3>A Simple Managed Component</h3>
<h5>Object Output: </h5>
<div id="Message" runat="server"/>
</body>
</html>
----------------------------------------
Men når jg køre den, så får jeg følgende fejl:
Compiler Error Message: CS0029: Cannot implicitly convert type 'int' to 'string'
Source Error:
Line 20: comp.tal2 = 5;
Line 21:
Line 22: Message.InnerHtml = comp.res();
Line 23: }
Line 24: </script>
