111,126
社区成员
发帖
与我相关
我的任务
分享
class Program {
public static void main(String[] args) {
Test1 myTest = new Test1();
myTest.setAge(18) = 18;
System.out.println(myTest.getAge());
}
}
class Test1 {
private int age;
public void setAge(int age) {
age = this.age;
}
public int getAge() {
return age;
}
}
using System; // 这是什么意思?
using System.Collections.Generic; // 这是什么意思?
using System.Text; // 这是什么意思?
namespace ConsoleApplication4 //命名空间有什么用?
{
class Program
{
static void Main(string[] args)
{
Test1 myTest = new Test1();
myTest.Age = 18;
Console.WriteLine(myTest.Age);
Console.Read();
}
}
class Test1
{
private int age;
// 这是 set, get 函数吗?怎么这样写?
public int Age
{
get { return age; } //搞不懂?
set { age = value; } //搞不懂?
}
}
}
using System; // 这是什么意思?****引用名字空间,在java中应该叫导入包(如io包等)
using System.Collections.Generic; // 这是什么意思?****引用泛型名字空间,
using System.Text; // 这是什么意思?
namespace ConsoleApplication4 //命名空间有什么用?////是你自定义的名字空间,利于源码维护与隔离,解决命名冲突等
{
class Program
{
static void Main(string[] args)
{
Test1 myTest = new Test1();
myTest.Age = 18;
Console.WriteLine(myTest.Age);
Console.Read();
}
}
class Test1
{
private int age;
// 这是 set, get 函数吗?怎么这样写?
public int Age
{
get { return age; } //搞不懂?//读这个字段
set { age = value; } //搞不懂?//向这个字段写数据
//其实就是两个函数
}
}
}