using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i = new int();
string a = " ";
Console.WriteLine("{0}{1}",a,i);
{
class Program
{
static void Main(string[] args)
{
int i = new int();
string a = " ";
Console.WriteLine("{0}{1}",a,i);
int[] b = new int[10];
Console.WriteLine(b[3]);
Console.WriteLine(b[3]);
structOne soInstanceOne = new structOne ();
Console.WriteLine("soInstanceOne:{0}:{1}", soInstanceOne.filed1, soInstanceOne.filed2);
Console.WriteLine("soInstanceOne:{0}:{1}", soInstanceOne.filed1, soInstanceOne.filed2);
structOne[] soArrayOne = new structOne[10];
Console.WriteLine("soArrayOne[]:{0}:{1}",soArrayOne[2].filed1,soArrayOne[2].filed2 );
soArrayOne[0].people = new string[4];
soArrayOne[0].people[0] = "男";
soArrayOne[0].people[1] = "18";
soArrayOne[0].people[2] = "Jack";
foreach (string peopleJack in soArrayOne[0].people)
{
Console.WriteLine(peopleJack);
}
Console.WriteLine("soArrayOne[]:{0}:{1}",soArrayOne[2].filed1,soArrayOne[2].filed2 );
soArrayOne[0].people = new string[4];
soArrayOne[0].people[0] = "男";
soArrayOne[0].people[1] = "18";
soArrayOne[0].people[2] = "Jack";
foreach (string peopleJack in soArrayOne[0].people)
{
Console.WriteLine(peopleJack);
}
soInstanceOne.people = new string[3];
soInstanceOne.people[0] = "女";
soInstanceOne.people[1] = "17";
soInstanceOne.people[2] = "Alice";
foreach (string peopleAlice in soInstanceOne.people)
{
Console.WriteLine(peopleAlice);
}
soInstanceOne.people[0] = "女";
soInstanceOne.people[1] = "17";
soInstanceOne.people[2] = "Alice";
foreach (string peopleAlice in soInstanceOne.people)
{
Console.WriteLine(peopleAlice);
}
Console.WriteLine(structOne.filed4);
soInstanceOne.StructOneMethodOne();
classOne Test = new classOne();
Console.WriteLine ("Test:");
Console.WriteLine ("{0}:{1}:{2}",Test.cFiled1,Test.cFiled2 ,Test.cFiled3 ); //打印0::false
Console .ReadLine ();
}
struct structOne
{
public int filed1; //执行这个语句structOne soInstanceOne = new structOne()之后, filed1的值初始化为0
public string filed2; //执行这个语句structOne soInstanceOne = new structOne()之后, filed2的值初始化为null
public string[] people;
//public sting[] people = { "男", "17", "Jack" };//结构中不能有实例字段初始值设定项,意思就是不能为实例字段赋值
//private int filed3 = 3; //不能有实例字段初始值设定项,意思就是不能为实例字段赋值
public static int filed4 = 4; //结构中可以为静态字段赋值
private const string conA = "conA"; //结构中可以为常数字段赋值,因为常数属于Static
private static string strName = "John"; //结构中可以为静态字段赋值
public static string[] anotherPeople = { "男", "17", "Tom" }; //结构中可以为静态数组赋值
public bool bResult;
public void StructOneMethodOne()
{
Console.WriteLine(conA);
Console.WriteLine(strName);
Console.WriteLine(bResult);
}
}
class classOne
{
public int cFiled1;
public string cFiled2;
public bool cFiled3;
}
}
}
本文转自terryli51CTO博客,原文链接:http://blog.51cto.com/terryli/520606 ,如需转载请自行联系原作者