【.net笔记09-11-16】:
Net简介:
Ado.net ß-----à jdbc
Net framework 运行环境 ß--à jvm
第一个.net程序:
using System;
using System.Collections.Generic;
using System.Text;
namespace CSharpAgain
{
class Program
{
static void Main1(string[] args)
{
Console.Write("Hello visual studio since from college first time");
Console.ReadLine();
}
}
}
测试string,以及while,for循环,switch语句:
using System;
using System.Collections.Generic;
using System.Text;
namespace CSharpAgain
{
class TestString
{
static void Main2(string[] args)
{
test1();
test2();
}
static void test1()
{
//Console.WriteLine("i'm in class TestString");
//String s = @"abc
//def\n";
String infos = @"
name:{0}
age:{1}
sex:{2}";
Console.WriteLine(infos, "gaoge", "23", "");
// Console.ReadLine();
for (int i = 0; i < 10; i++)
{
Console.WriteLine("i is: " + i);
if (i == 5)
{
goto breakout;//传说中的goto语句
}
}
breakout:
Console.WriteLine("this is breakout from goto ");
Console.ReadLine();
}
static void test2()
{
string s1 = "";
bool b = true;
while(b){
switch((s1 = Console.ReadLine()))//这个在java里是不允许的
{
case "exit":
b = false;
break;
default:
Console.WriteLine("your input is: " + s1);
break;
}
}
}
}
}
.net中的继承机制:
using System;
using System.Collections.Generic;
using System.Text;
namespace CSharpAgain
{
class TestBase
{
static void Main(string[] args){
Person p = new Student("gaoge",23);
Student s = new Student("lisi",29);
Console.WriteLine("p.name is: " + p.Name);
p.Name = "zhang san";
Console.WriteLine("s.name is: " + s.Name + "s.age is: " + s.Age);
Console.ReadLine();
}
}
class Person{
private string name;
public Person(string name)
{
this.name = name;
}
public String Name{
set{
this.name = value;//这个value很有特点
}
get{
return this.name;
}
}
}
class Student : Person
{
private int age;
public int Age
{
get
{
return this.age;
}
set
{
this.age = value;
}
}
public Student(String name)
: base(name)
{
}
public Student(String name,int age)
: base(name)
{
this.age = age;
}
}
}