2016-08-25 146 views
0

如何繼承類,當我嘗試繼承它時會給我一個錯誤。C#ASP.NET繼承

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

public partial class expresion2 : System.Web.UI.Page 
{ 
    public String nombre, email, telefono, contra, usuario; 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     nombre = txtNombre.Text; 
     email = txtEmail.Text; 
     telefono = txtTel.Text; 
     contra = txtContra.Text; 
     usuario = txtUser.Text; 


    } 
} 

當我嘗試繼承 「expresion2」 它給了我2016

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

public partial class mostrar2 : expresion2 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 
} 

enter image description here

回答

6

你mostrar2和表達式類不是一個命名空間中定義的VS工作室編譯錯誤。

正確的定義如下:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

namespace myNamespace 
{ 
    public partial class expresion2 : System.Web.UI.Page 
    { 
     public String nombre, email, telefono, contra, usuario; 

     protected void Page_Load(object sender, EventArgs e) 
     { 
      nombre = txtNombre.Text; 
      email = txtEmail.Text; 
      telefono = txtTel.Text; 
      contra = txtContra.Text; 
      usuario = txtUser.Text; 


     } 
    } 
} 

而且;

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

namespace myNamespace 
{ 
    public partial class mostrar2 : expresion2 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 

     } 
    } 
} 
+0

它不起作用!仍然給出相同的錯誤,是否有另一種方法來從expresion2繼承變量到mostra2? – Takami