回 帖 发 新 帖 刷新版面

主题:为什么vb可以c#不行

<%@ Page Language="VB" %>
<script runat="server">

    dim s1 as string
    Sub RadioButton_CheckedChanged(sender As Object, e As EventArgs)
    s1=sender.Text
    End Sub

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <asp:RadioButton id="RadioButton1" runat="server" OnCheckedChanged="RadioButton_CheckedChanged" AutoPostBack="True" GroupName="r1" Text="3"></asp:RadioButton>
        <br />
        <asp:RadioButton id="RadioButton3" runat="server" OnCheckedChanged="RadioButton_CheckedChanged" AutoPostBack="True" GroupName="r1" Text="4"></asp:RadioButton>
        <br />

     
        <%= s1%>
    
    </form>
</body>
</html>
vb编译通过,显示也正常
<%@ Page Language="C#" %>
<script runat="server">

    // Insert page code here
    //
    string s1;
    void RadioButton_CheckedChanged(Object sender, EventArgs e) {
    s1 = sender.Text;
    }

</script>
<html>
<head>
</head>
<body>
    <form runat="server">
        <asp:RadioButton id="RadioButton1" runat="server" GroupName="r1" AutoPostBack="True" OnCheckedChanged="RadioButton_CheckedChanged" Text="4"></asp:RadioButton>
        <br />
        <asp:RadioButton id="RadioButton3" runat="server" GroupName="r1" AutoPostBack="True" OnCheckedChanged="RadioButton_CheckedChanged" Text="5"></asp:RadioButton>
       
        <br />
        <%= s1%>
        
    </form>
</body>
</html>
c#就不行,提示Object 没有text


是为什么呀?

回复列表 (共2个回复)

沙发

VB.Net可以隐性转换Object(和VB6相似),而C#不可以。

因为Object没有Text属性,所以不能经过编译。

板凳

我刚刚建立了一个asp.net讨论QQ群组11440220,欢迎加入,c#爱好者的优先考虑呀!

我来回复

您尚未登录,请登录后再回复。点此登录或注册