现在的位置: 首页 > 综合 > 正文

C#基础学习2—总结

2013年10月12日 ⁄ 综合 ⁄ 共 804字 ⁄ 字号 评论关闭

1.函数
  返回值类型(int ,string ,......,void(无返回值时))  函数名(参数列表)
  int ReadInt(string msg)
  {
    return 值;
  }
  return 立即返回
  函数重载(参数个数或者参数类型不同,构成函数)
  static int Add(int a,int b)
  {
    return a+b;
  }
  static string Add(string a,string b)
  {
    return a+b;
  }
2.可变参数
  static int Max{params int[] array}
   {
      int max=0;
      foreach(int i in array)
      {
        if(i>max)
          {
            max=i;
          }
      }
   }
  调用 Max(1212,232,231),求最大的数,可输入任意多大值
3.函数ref,out参数
  static void Sawp(int a,int b)//操作的是复制品,不会改变其原来的值,复制进来的
  {
    int temp=a;
    a=b;
    b=temp;
  }

 static void  Swap(ref int a,ref int b)//传进来是变量本身了,会改变,使用之前必须给变量赋值
   {
     int temp=a;
     a=b;
     b=temp;
   }
4.字符串的处理
  char a='c'; string b="f"; 区别
  string c=""; string c=null 区别(一个是长度为0,一定是没有)
  判断字符串是否为空(常用IsNullOrEmpty)
  if(s==null||s==""||s==string.Empty)
  if(string.IsNullOrEmpty)
  string.ToLower()   string.Trim()   string.Equal()
 

抱歉!评论已关闭.