主题:初学求助:C# Invalid token ';'
[b]问题出在下面三行的“;”上[/b]:
private String_Name; //姓名字段
private int_Age; //年龄字段
private Genders_Gender; //性别字段
希望各位大侠能帮我看下,是什么问题,谢谢~
[b]原代码如下[/b]:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClassConstructedFunction_3_5
{
//性别定义枚举
public enum Genders
{
Female = 0,
Male = 1
}
public class Person
{
//重写默认构造函数
public Person()
{
this._Name="默认姓名";
this._Age=20;
this._Gender=Genders.Male;
}
//初始化姓名的构造函数
public Person(string strName)
{
this._Name=strName;
this._Age=20;
this._Gender=Genders.Male;
}
//初始化姓名和年龄的构造函数
public Person(string strName,int age)
{
this._Name=strName;
this._Age=age;
this._Gender=Genders.Male;
}
private String_Name; //姓名字段
private int_Age; //年龄字段
private Genders_Gender; //性别字段
public void IntroduceMyself()
{
System.Console.WriteLine("我叫:{0},性别:{1},年龄:{2}",this._Name,this._Gender,this._Age);
}
}
class Program
{
static void Main(string[] args)
{
Person aPerson=new Person();
aPerson.IntroduceMyself();
aPerson=new Person("张三");
aPerson.IntroduceMyself();
aPerson=new Person("李四",50);
aPerson.IntroduceMyself();
}
}
}
[b]报错:[/b]
Error 1 Invalid token ';' in class, struct, or interface member declaration E:\projects\practice\ClassConstructedFunction_3-5\ClassConstructedFunction_3-5\Program.cs 41 28 ClassConstructedFunction_3-5
Error 2 Invalid token ';' in class, struct, or interface member declaration E:\projects\practice\ClassConstructedFunction_3-5\ClassConstructedFunction_3-5\Program.cs 42 24 ClassConstructedFunction_3-5
Error 3 Invalid token ';' in class, struct, or interface member declaration E:\projects\practice\ClassConstructedFunction_3-5\ClassConstructedFunction_3-5\Program.cs 43 31 ClassConstructedFunction_3-5
private String_Name; //姓名字段
private int_Age; //年龄字段
private Genders_Gender; //性别字段
希望各位大侠能帮我看下,是什么问题,谢谢~
[b]原代码如下[/b]:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClassConstructedFunction_3_5
{
//性别定义枚举
public enum Genders
{
Female = 0,
Male = 1
}
public class Person
{
//重写默认构造函数
public Person()
{
this._Name="默认姓名";
this._Age=20;
this._Gender=Genders.Male;
}
//初始化姓名的构造函数
public Person(string strName)
{
this._Name=strName;
this._Age=20;
this._Gender=Genders.Male;
}
//初始化姓名和年龄的构造函数
public Person(string strName,int age)
{
this._Name=strName;
this._Age=age;
this._Gender=Genders.Male;
}
private String_Name; //姓名字段
private int_Age; //年龄字段
private Genders_Gender; //性别字段
public void IntroduceMyself()
{
System.Console.WriteLine("我叫:{0},性别:{1},年龄:{2}",this._Name,this._Gender,this._Age);
}
}
class Program
{
static void Main(string[] args)
{
Person aPerson=new Person();
aPerson.IntroduceMyself();
aPerson=new Person("张三");
aPerson.IntroduceMyself();
aPerson=new Person("李四",50);
aPerson.IntroduceMyself();
}
}
}
[b]报错:[/b]
Error 1 Invalid token ';' in class, struct, or interface member declaration E:\projects\practice\ClassConstructedFunction_3-5\ClassConstructedFunction_3-5\Program.cs 41 28 ClassConstructedFunction_3-5
Error 2 Invalid token ';' in class, struct, or interface member declaration E:\projects\practice\ClassConstructedFunction_3-5\ClassConstructedFunction_3-5\Program.cs 42 24 ClassConstructedFunction_3-5
Error 3 Invalid token ';' in class, struct, or interface member declaration E:\projects\practice\ClassConstructedFunction_3-5\ClassConstructedFunction_3-5\Program.cs 43 31 ClassConstructedFunction_3-5