namespace MyNamespace
{
class Student
{
private string _name;
private int _phoneNo;
private string _address;
private string _occupation;
private string _courseOfStudy;
private int _duration;
private string _uploadPicture;
}
public string Name
{
get { return _name;}
set { _name = value;}
}
public int PhoneNumber
{
get { return _phoneNo;}
set { _phoneNo = value;}
}
public string Address
{
get { return _address;}
set { _address = value;}
}
public string Occupation
{
get { return _occupation;}
set { _occupation = value;}
}
public string CourseOfStudy
{
get { return _courseOfStudy;}
set { _courseOfStudy = value;}
}
public int Duration
{
get { return _duration;}
set { _duration = value;}
}
public string Uploadpicture
{
get { return _uploadpicture;}
set { _uploadpicture = value;}
}
public Student()
{
_name = "";
_phoneNo = "";
_address = "";
_occupation = "";
_courseOfStudy = "";
_duration = "";
_uploadPicture = "";
System.Windows.Forms.MessageBox.Show("Called Constructor")
}
public Student (String name, int phoneNo, string address, string occupation, string courseOfStudy, int duration, string uploadPicture)
{
_name = name;
_phoneNo = phoneNo;
_address = address;
_occupation = occupation;
_courseOfStudy = courseOfStudy;
_duration = duration;
_uploadPicture = uploadPicture;
}
}
質問する
281 次
4 に答える
5
C# では、クラスの外部でメソッドを宣言することはできません。
于 2013-10-25T11:15:35.040 に答える
0
他の人が指摘したように、すべてのプロパティとコンストラクターをクラスの外に置きました。また、フィールド値をカプセル化していないため、プロパティを処理するための不要なコードが大量にあります。そのため、自動プロパティを使用するように書き換えることができます。次の書き換えを試してください。
namespace MyNamespace
{
class Student
{
public string Name { get; set; }
public int PhoneNumber { get; set; }
public string Address { get; set; }
public string Occupation { get; set; }
public string CourseOfStudy { get; set; }
public int Duration { get; set; }
public string UploadPicture { get; set; }
public Student() : this("", 0, "", "", "", 0, "")
{
MessageBox.Show("Called Constructor");
}
public Student(String name, int phoneNo, string address, string occupation, string courseOfStudy, int duration, string uploadPicture)
{
Name = name;
PhoneNumber = phoneNo;
Address = address;
Occupation = occupation;
CourseOfStudy = courseOfStudy;
Duration = duration;
UploadPicture = uploadPicture;
}
}
}
于 2013-10-25T11:29:17.953 に答える
0
最初にそれを削除します}
その下のプロパティがクラスの外に表示されます。
于 2013-10-25T11:19:42.737 に答える
-1
メンバーは現在、クラス内にありません。_uploadPicture; の後ろの中括弧。} は最後にある必要があります。
また、他にもいくつかの間違いがあります:
- _uploadpicture は、パブリック文字列 Uploadpicture の _uploadPicture である必要があります
- 文字列で int を初期化しようとしています (_phoneNo = "";)
修正されたクラスは次のとおりです。
namespace MyNamespace {
class Student {
private string _name;
private int _phoneNo;
private string _address;
private string _occupation;
private string _courseOfStudy;
private int _duration;
private string _uploadPicture;
public string Name {
get {
return _name;
}
set {
_name = value;
}
}
public int PhoneNumber {
get {
return _phoneNo;
}
set {
_phoneNo = value;
}
}
public string Address {
get {
return _address;
}
set {
_address = value;
}
}
public string Occupation {
get {
return _occupation;
}
set {
_occupation = value;
}
}
public string CourseOfStudy {
get {
return _courseOfStudy;
}
set {
_courseOfStudy = value;
}
}
public int Duration {
get {
return _duration;
}
set {
_duration = value;
}
}
public string Uploadpicture {
get {
return _uploadPicture;
}
set {
_uploadPicture = value;
}
}
public Student() {
_name = "";
_phoneNo = 0;
_address = "";
_occupation = "";
_courseOfStudy = "";
_duration = 0;
_uploadPicture = "";
System.Windows.Forms.MessageBox.Show("Called Constructor");
}
public Student(string name, int phoneNo, string address, string occupation, string courseOfStudy, int duration, string uploadPicture) {
_name = name;
_phoneNo = phoneNo;
_address = address;
_occupation = occupation;
_courseOfStudy = courseOfStudy;
_duration = duration;
_uploadPicture = uploadPicture;
}
}
}
于 2013-10-25T11:23:59.500 に答える