C#变量---xdd
2024-09-01 15:44:18
cshape(c#)学习笔记
1. string str1=Console.ReadLine();//键盘输入的默认为字符串
2. Console.WriteLine('你的成绩是'+a+'分');
Console.WriteLine("a={0},b={1}",a,b)
for(i=;i<=;i++) //for 的格式
{
}
3. while()
4. if switch goto
5. 交换(方法))函数的写法与引用
static void Swap(inta,intb)//存疑,可能不是值传递
{
int t;//t的作用范围尽在此大括号内
t=a;a=b;b=t;
}
这样在主函数中交换a,b需要
static void Main(string[] args)
int a=;
int b=;
Swap(ref a, refb)
这样在主函数中交换a,b需要
Swap(a,b)
另外一种写法: //ref共用内存
static void Swap(ref int a,ref int b)//
{
int t;//t的作用范围尽在此大括号内
t=a;a=b;b=t;
}
这样在主函数中交换a,b需要
static void Main(string[] args)
int a=;
int b=;
Swap(ref a, refb)
6. 重载:相同的函数名,但是类型不一样,如
static void Swap(ref int a,ref int b) //交换两个数
static void Swap(ref string a,ref string b) //交换两个字符串
write by xdd 2019/07/20
7. 变量类型
int i=1;
double a=3.14159,b=c=d=,e;
bool x=true;
Char ch1='x';
string str1='fengmy';
conse double PI=3.1415926;/定义常数
% //求余数
\n换行 \b退格 \\为右斜杠
int a1=int.Parse(str1); //字符串转为数值方法=子函数
&&与 ||或 !非
8. 变量的有效范围
局部变量:在类的方法中定义的变量,只在当前方法中有效,不能用于该类其它方法
在类(不在方法中)中定义的变量成为成员变量,可以分为实例变量、静态变量(也成类变量),如下:
class Test
{
int x=;//实例变量,在整个类中有效
static int y=;//静态变量,所有类中都有效
}
write by xdd 2019-08-19 23:45:55
最新文章
- poj 并查集
- MapReduce 重要组件——Recordreader组件 [转]
- ubuntu cenots 禁止本地登陆
- unity中怎样获取全部子物体的组件
- Java传参
- SQL Server @@ERROR 用法
- SSH服务(一)
- 程序员需要有多懒 ?- cocos2d-x 数学函数、常用宏粗整理
- golang http.client 遇到了 Connection reset by peer 问题
- wget命令使用报错 certificate common name &#39;xxx&#39; doesn&#39;t match requestde host name
- Linux在VirtualBox的网络设置
- JQuery Dom的基本操作
- [CodeForces 372A] Counting Kangaroos is Fun
- Linux操作系统原理
- vscode中live server插件的Go Live不显示问题
- 安装lsb_release
- CDH5.2+CM5.2+impala2+Spark1.1 集群搭建基础环境准备
- 单精度浮点数(float)加法计算出错
- vs 你不得不会的调试方式
- echarts中跨域动态获取数据时,当某些对应的数据为空时,鼠标滑动到所在位置卡死