结构体类型是一种值类型,类类型是一种引用类型
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
struct student
{
public int no;
public string name;
public string phone;
public student(int stu_no, string stu_name, string stu_phone)
{
no = stu_no;
name = stu_name;
phone = stu_phone;
}
}
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
student stu = new student(61101, "zhangsan", "111111");
Console.WriteLine(stu.no);
Console.WriteLine(stu.phone);
Console.WriteLine(stu.name);
Console.ReadLine();
}
}
}
数组类型
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/*
class test
{
string [] m1; // 一维字符串数组
string [,] m2 //二维字符串数组
string [, ,] m3 //三维字符串数组
short [][] n1 //锯齿形数组n1
int [][][] n2 //三层数组n2;
}
*/
namespace aaa //lx424
{
class arraytest
{
static void ain()
{
int[] arr = new int[5];
for (int i = 0; i < arr.Length; i++)
arr[i] = Convert.ToInt32( Console.ReadLine() );
for (int i = 0; i < arr.Length; i++)
Console.WriteLine("{0}", arr[i]);
}
}
}
数组做参数
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class test2
{
static void t(char[] arr) { }
public static void Main()
{
t(new char[] { 'a', 'b', 'c' }); //必须经过初始化
Console.WriteLine("输出");
Console.ReadLine();
}
}