变量要先声明再使用
变量要先初始化再使用(读取)
第一次赋值bei
变量要先声明再使用
变量要先初始化再使用(读取)
第一次赋值bei
int代表整数
age代表变量名
home end 定位光标到起始和结束位置
shift可以多选代码
ctrl 单独多选文件
ctrl+A全选代码
insert覆盖模式代码
代码的编译
把代码翻译成机器可以识别的文件
机器语言:010101101
高级语言:c#等
1.//3.6
2.//3
3.//
4.√
5.b× d
6.×
7.
\\输出后是\
转印字符\
基本语法
//加注释
快捷键ctrl+k,ctrl+c
取消注释Ctrl+k,ctrl+u
/*sdf
sdf
*/组合注释。
开始调试F5
代码执行顺序从上到下
英文输入法
1using System; //注释:引入命名空间
2
3namespace _001_开始
4{
5 class Program6
6 {
7 static void Main(string[] args)
8 {
9 Console.WriteLine("Hello World!");
10 Console.WriteLine("Hello World!");
11 }
12 }
13}
C# 是一门非常好的语言
方法的创建与调用在课时100和课时101中讲解。
想了半天以为要长篇大论结果就几行
for(int i =1; i <= 9; i++)
{
for (int a = 1; a <=i; a++)
{
Console.Write("{0}x{1}={2}\t", a, i, a * i);
}
Console.WriteLine();
}
-1=a+bjjjj
int n = Convert.ToInt32(Console.ReadLine());
for (int a = 1; a < n + 1; a++)
{
for (int i = 0; i < n; i++)
{
Console.Write("*");
}
Console.WriteLine();
for (int temp = 1; temp < a + 1; temp++)
{
Console.Write(" ");
}
}
虽然方法不一样但是看了一下老师的觉得老师的跳楼更清晰
//创建变量
//创建了一个容器,容器的名字叫做age,容器的类型是int
//integer;声明了一个变量,变量的名字叫age
int age;//int是变量类型,age是变量名字
//变量的赋值,往容器中放东西
//等号的意思就是把右边的东西放到左边的容器里面
age = 10;
//int 是整数类型,double是小数(浮点),char是字符类型
double age2;
char age3;
//然后英文字母,数字,下划线
//命名规则:首先数字可以在命名中出现,但是不能作为名字的第一个字符
int count;
double ave;
double height;
int total;
double temprature;
//把左边的数字放到了右边的容器中
//赋值
total = 4;
//通过变量类型告诉系统需要多大的一个容器
//内存的地址会和变量名对应起来,管理员会分配内存,内存会对应一串数字,数字作为地址会和变量名字对应起来
//int a = 1;
//赋值的覆盖
//当a已经有了一个数据之后,我们再给他一个新的数据,那么新的数据会将旧的值覆盖掉
//旧的数据会被清空,然后放上新的数据
int a = 1;
a = 3 + 7 - 2;
int b = 3;
b = b + 1;
Console.WriteLine (a);//括号中没有引号,输出的是值;有引号的话,输出的是字符串
Console.WriteLine(b);
调用方法用()
ctrl+c ctrl+k注释代码
ctrl+k ctrl+u取消注释
using System;
namespace _0001
{
internal class Program
{
static void Main(string[] args)
{
Random rd = new Random();
Console.WriteLine(rd.Next(1, 10));
}
}
}
using System;//注释:引入命名空间//
namespace _001_开始//名字是不可以以数字开头的,所以会自动生成一个下划线,一般命名不使用中文
//namespace 是定义了一个命名空间,对代码进行一个分类
{
class Program//class是一个类,然后program是类的名称,会和文件名称保持一致,命名空间和项目名称保持一致
{
static void Main(string[] args)//在类下面创建了一个方法,名叫main
{
//Console.WriteLine("Hello World!");//然后在方法下面创建了代码
// //向控制台显示一行字符
//Console.WriteLine("i will always be by your side"); //输出语句
//console是一个类,writeline是一个方法
//writeline意思就是在调试控制台书写文字的意思
/*这是注释
*/
//ctrl k ctrl c 注释快捷键
//ctrl k ctrl u 取消注释
//Console.Write("hello world!");
//Console.Write("zhangsan");//wrire和writeline 的区别就是,前者不会换行,后者输出换行
//Console.WriteLine("he\tllo \nworld!");//\t代表table键,制表符,\n为换行符
C#练习
Program、Console等划红圈的表示类
Main、Writeline等划绿圈的表示方法
注释快捷键:添加注释ctrl+k ctrl+c 取消注释:ctrl+k ctrl+u
Colnsole.
只判断小于的情况代码要更简洁xie
//从小到大的数组插入一个数排序
string str = Console.ReadLine();
string[] strArray = str.Split(" ");
int[] intArray = new int[strArray.Length];
for (int i = 0; i < strArray.Length; i++)
{
int number = Convert.ToInt32(strArray[i]);
intArray[i] = number;
}
int x = Convert.ToInt32(Console.ReadLine());
int xIndex = 0;
for (int i = 0; i < intArray.Length; i++)
{
if (intArray[i] >= x)
{
xIndex = i;
break;
}
else
{
xIndex = intArray.Length;
}
}
int[] newIntArray = new int[intArray.Length + 1];
for (int i = 0; i < newIntArray.Length; i++)
{
if (i < xIndex)
{
newIntArray[i] = intArray[i];
}
else if (i == xIndex)
{
newIntArray[i] = x;
}
else
{
newIntArray[i] = intArray[i - 1]; //1 3 4 5
}
}
foreach (int t in newIntArray)
{
Console.Write(t + " ");
}
struct Vector3
{
public double x;
public double y;
public double z;
public double Distance()
{
double r = Math.Sqrt(x * x + y * y + z * z);
Console.WriteLine(r);
return r;
}
}
static void test11()
{
Vector3 vector1;
vector1.x = 1;
vector1.y = 2;
vector1.z = 2;
vector1.Distance();
}
static void Main(string[] args)
{
test11();
}
static int F2(int n)
{
if (n == 1)
{
return 1;
}
return F2(n-1)+n*n;
}
static void test06()
{
int sum = 0;
for (int i = 1; ; i++)
{
sum = sum + i * i;
if (sum>=2000)
{
Console.WriteLine(i-1);
Console.WriteLine(sum);
break;
}
}
Console.WriteLine(sum);
int j = 1;
while (true)
{
if (F2(j)>=2000)
{
break;
}
j++;
}
Console.WriteLine("j-1="+(j-1));
}