笔记
计算机内存:
在程序进入内存的时候,我们把程序占据的内存认为分成4部分.
- 堆→存储引用类型 数组 字符串 class 等
- 栈→存储值类型的值,所有方法和变量都在栈中 程序运行在栈中
- 全局==>全局变量
- 代码==>存放代码
进制:
- 十进制转二进制==>除二取余法
- 二进制转换10进制==>按位展开法的逆向 x*2^n
在编程中默认编码格式为utf8 utf8是一种文件的编码格式,若编码格式不对应就会产生乱码的情况
UTF8 –> UTF8
C#会形成一个称谓IL的中间语言, 这个中间语言会在我们学习热更新的时候用到
unity常用的:
1. int 4
2. stirng
3. float 4
4. bool 1
5. class
6. char 2
7. double 8
8. enum 表示枚举类型 常用于unity编程 状态机
只要在int类型表示范围内统统int + - 21亿 -2147483648 + 2147483647
运算符:
/ %
! ==
^ | & 位运算
&& || ! 用于if判断逻辑中
++i i++ 在赋值号存在的情况下, 没有赋值号 ++i i++ 都是自增
i++ 先赋值在自增
++i 先自增,在赋值
X = (bool) ?Number01:Number02; 相当于一个简单的if else
当bool为真 X = Number01
当bool为假 X = Number02
表达式: 用赋值号链接的式子称谓表达式 A = B
foreach本质是迭代器,迭代器本身就是不能进行修改的 所以foreach不能修改, 要想修改数组必须使用for循环
数组: 相同数据类型的组合
1. 特性数组长度固定 在使用数组的时候必须固定大小
2. 数组是引用类型
3. 索引从0开始
4. 遍历数组使用foreach还是使用for 都行
5. 修改数组使用foreach or for
homework:
1. 用C#编程实现10进制转换2进制 用户输入一个10进制数.进过程序计算得出2进制
1. 用户输入其他东东会要求重新输入 10a a10 10!
2. 系统随机产生10个二进制数值, 经过计算得出对应的10进制
3. 1~30 二进制背会 明天抽查
4. 每一个人准备一个云笔记, 把学过的知识点全部总结在云上面, 每天上午上课之前用20分钟看一遍!
5. 模仿网页登录的验证码系统 要求6位,必须包含大写/小写/数字 用户输入的时候不区分大小写
6. 使用unity做一个类似于跑马灯效果 q 代表停止跑马灯效果
作业
1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/*1. 用C#编程实现10进制转换2进制 用户输入一个10进制数.经过程序计算得出2进制
1. 用户输入其他东东会要求重新输入 10a a10 10!*/
namespace _9._10day01练习
{
class Program
{
static void Main(string[] args)
{
while (true)
{
//bool b;
Console.WriteLine("请输入一个十进制数");
string a = Console.ReadLine();
try
{
Convert.ToInt32(a);
string d = Convert.ToString(Convert.ToInt32(a), 2);
Console.WriteLine("转换为二进制为:" + d);
//b = true;
}
catch
{
Console.WriteLine("您的输入有误,请重新输入");
//b = false;
}
/*if (b==true)
{
int c = Convert.ToInt32(a);
string d = Convert.ToString(c, 2);
Console.WriteLine("转换为二进制为:" + d);
}
else
{
Console.WriteLine("您的输入有误,请重新输入");
}*/
}
}
}
}
2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//2. 系统随机产生10个二进制数值, 经过计算得出对应的10进制
namespace _2
{
class Program
{
static void Main(string[] args)
{
Random rd = new Random();
//Console.WriteLine("随机生成的二进制数为:");
for (int i = 0; i < 10; i++)
{
int a = rd.Next(0, 99);
string b =Convert.ToString(a, 2);
Console.WriteLine(b);
Console.WriteLine(Convert.ToInt32(b, 2));
}
Console.ReadKey();
}
}
}
5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 验证码
{
class Program
{
static void Main(string[] args)
{
//三种字符 三个数组 A a 1
// 数字
//大写
//小写
// 6
//ascii 就是一种编码格式
//Console.WriteLine((char)81);
Random r = new Random( );
// 48 ~57 0
//65 ~90 A
// 97 ~122 a
//必须保证三种情况满足 0 -->A 1 --> a 2--> 0
bool[] isDone = {true, true, true};
char[] RandomChar = new char[6];
int indexChar = 0; // 0 1 2
ReCalc:
//确保初始化 初始值位 true
for (int i = 0; i < isDone.Length; i++)
{
isDone[i] = true;
}
//计算每一位
for (int i = 0; i < RandomChar.Length; i++)
{
//6
indexChar = r.Next(0, 3); // 状态值 0 大写 1 小写 2 数字
switch (indexChar)
{
case 0:
RandomChar[i] = (char)r.Next(65, 91); // 产生随机值 大写
if (isDone[indexChar]) // 判断是有该类型的值 若为true 就代表该数值没有被取出
isDone[indexChar] = false; // 若该值为false 代表已经有了这个A类型
break;
case 1:
RandomChar[i] = (char)r.Next(97, 123); // 小写
if (isDone[indexChar])
isDone[indexChar] = false;
break;
case 2:
RandomChar[i] = (char)r.Next(48, 58); // 数字
if (isDone[indexChar])
isDone[indexChar] = false;
break;
}
}
//for
if (isDone[0] || isDone[1] || isDone[2])
{
//不满足条件
goto ReCalc;
}
ReInput:
for (int i = 0; i < RandomChar.Length; i++)
{
Console.Write(" {0} ",RandomChar[i]);
}
Console.WriteLine();
//判断用户输入
string userInput = Console.ReadLine();
if (userInput.Length != 6)
{
Console.WriteLine("输入的格式错误");
return;
}
for (int i = 0; i < userInput.Length; i++)
{
if (char.ToUpper(RandomChar[i]) != char.ToUpper(userInput[i]))
{
Console.WriteLine("输入的不对");
goto ReInput;
}
}
}
}
}