C#变量---xdd

cshape(c#)学习笔记

 

1. string str1=Console.ReadLine();//键盘输入的默认为字符串

2.  Console.WriteLine('你的成绩是'+a+'分');

  Console.WriteLine("a={0},b={1}",a,b)

for(i=3;i<=10;i++)   //for 的格式
{
}

3. while()

4. if  switch goto   

5. 交换(方法))函数的写法与引用

1 static void Swap(inta,intb)//存疑,可能不是值传递
2 {
3 int t;//t的作用范围尽在此大括号内
4 t=a;a=b;b=t;
5 }
这样在主函数中交换a,b需要
static void Main(string[] args)
  int a=1;
  int b=2;
  Swap(ref a, refb)
这样在主函数中交换a,b需要
Swap(a,b)
另外一种写法:       //ref共用内存
1 static void Swap(ref int a,ref int b)//
2 {
3   int t;//t的作用范围尽在此大括号内
4   t=a;a=b;b=t;
5 }
这样在主函数中交换a,b需要
static void Main(string[] args)
  int a=1;
  int b=2;
  Swap(ref a, refb)

6. 重载:相同的函数名,但是类型不一样,如 

1  static void Swap(ref int a,ref int b)            //交换两个数
2  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;/定义常数
% //求余数 换行  退格  \为右斜杠
int a1=int.Parse(str1); //字符串转为数值方法=子函数
&&与  ||或  !非

8. 变量的有效范围

  局部变量:在类的方法中定义的变量,只在当前方法中有效,不能用于该类其它方法

  在类(不在方法中)中定义的变量成为成员变量,可以分为实例变量、静态变量(也成类变量),如下:

1  class Test
2   {
3      int x=45;//实例变量,在整个类中有效
4    static int y=90;//静态变量,所有类中都有效
5   }

write by xdd  2019-08-19  23:45:55


 


转载仅为学习,不会商用。
欢迎转载原创,附文链接。
原文地址:https://www.cnblogs.com/xdd1997/p/11219434.html