今日继续我的C#学习之路
设置启动项目:
Visual Studio 无法直接启动带有"类库输出类型"的项目。若要调试此项目,请在此解决方案中添加一个引用库项目的可执行项目。将这个可执行项目设置为启动项目问题解决
调试学习时的一个小插曲,有时会遇到这个报错,其实是没有启动项目

解决方法就是设置你的项目为启动项目就可以了:
或者是你没有设置程序输出类型,这需要右击项目进入属性进行设置:

设置正确的输出类型就行了:
设置成功后可以在左上角叉掉关闭:

Console.ReadLine();
这句语句是等待键盘输入,因为我设置的输出类型是控制台应用程序,程序结尾添加这行是为了防止电脑直接运行出结果就自动把控制台窗口关闭了,方便我们人能完整看完结果

一维数组:
定义格式:
类型标识符 [ ]数组名=new 类型标识符[整形表达式];
cs
int[] a = new int[100];
或分开定义:
类型标识符 [ ] 数组名;
数组名=new 类型标识符[整形表达式];
cs
int[] a ;
a = new int[100];
一维数组初始化同时的赋值:
类型标识符 [ ] 数组名 = new 类型标识符[整形表达式]{值1,值2,...,值n};
cs
int[] a = new int[10] {1,2,3,4,5,6,7,8,9,10};
一维数组的赋值:
cs
int[] a = new int[10];
for (int i = 0; i < 10; i++)
{
a[i] = i;
Console.WriteLine(a[i]);
}

二维数组:
定义格式:
类型标识符 [,]二维数组名 =new 类型标识符 [整形表达式1,整形表达式2];
以下为定义2行3列的二维数组,一共有2*3=6个数组元素
cs
int[,] a = new int[2, 3];
或者 :
cs
int[,] a;
a = new int[2, 3];
二维数组的赋值:
二维数组的初始化赋值与双层循环输出:
cs
namespace shuzu
{
public class Class1
{
static void Main(string[] args)//程序的入口方法:首先被执行的
{
int[,] a= new int[2, 3] { { 1,2,3},{ 4,5,6} };
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3; j++)
{
Console.WriteLine(a[i,j]+"\n");
}
}
Console.WriteLine("现在正式开始学习C#开发");
Console.ReadLine();
}
}
}
运行结果:
Console.WriteLine(a[i,j]+"\n");
表示输出a[i,j]的值并+"\n" 换行

顺序赋值:
cs
namespace shuzu
{
public class Class1
{
static void Main(string[] args)//程序的入口方法:首先被执行的
{
int[,] a;
a = new int[2, 3];
a[0, 0] = 6;
a[0, 1] = 5;
a[0, 2] = 4;
a[1, 0] = 3;
a[1, 1] = 2;
a[1, 2] = 1;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 3; j++)
{
Console.WriteLine(a[i, j] + "\n");
}
}
Console.WriteLine("现在正式开始学习C#开发");
Console.ReadLine();
}
}
}
运行结果:
