C#概念总结(二)

1、C#的方法:<access Specifier>  <Return Type>< Method Name>(Parmeter list){     method Body}

   其中 Method Name是一个唯一的标志符,且大小写敏感, parmeter list 参数列表,该参数用来接收和传递方法使用的参数,参数列表是指方法的参数类型,顺序和数量,参数是可选的,一个方法可以不包函参数。

 附录:今天做实验的时候发现一个奇怪的现象,就是在kali linux 中使用 kali  U 盘时候,就U盘的格式修改成监听模式,即混杂模式后,在Windows,也就是自己的宿主机上连接在五香网卡会失效。

2、C#参数传递 当调用带有参数的方法的时候,我们需要向方法传递参数,C#中有三种方式向方法传递参数。分别是值参数、引用参数、输出参数。

       值参数: 这种方式 赋值参数的实际值给函数的形式参数,实参和形参使用两个不同的内存地址,在这中情况之下,当形参发生改变的时候,不会影响实参的值。从而保证了实参的安全性。

     引用参数:  这种方式赋值参数的内存地址给引用形式参数,当形式蚕食发生改变的时候,同时也改变了实参的值。

     输出参数:   这种方式返回多个值。

  引用传递参数; 是对变量的内存地址的引用,当按因用户传递参数的式,与值参数不同的是,他不会为这些参数创建一个新的存储的位置,引用参数表示提供给方法的参数具有相同的位置。  在C#中使用C#关键字声明引用参数。

   输出传递参数:

      return语句可以用在只从函数返回一个值。

 

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            numberManinputlation Te = new numberManinputlation();
            int a = 100;
            Console.WriteLine(" 调用之前输出{0}", a);
            

            Te.getValue(out a);
            Console.WriteLine("调用之后输出{0}", a);
            Console.ReadKey();
            int c, b;
            Te.getValues(out c,out b);
            Console.WriteLine("c: {0}", c);
            Console.WriteLine("b:{0}", b);
            Console.ReadLine();
        }
    }
    class numberManinputlation {
        public void getValue(out int x) {
            int temp=34;
            x = temp;
        }
        public void getValues(out int a, out int b) {
            Console.WriteLine("please input noe number");
            a = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("please input second number");
            b = Convert.ToInt32(Console.ReadLine());
        }
    }
}
3、C#可空类型:

      nullabe 类型,表示基础值类型正常范围内的值,再加上一个null 值。类似的nullable<bool> 表示被赋值为true或false或者 null

4、C#数组 (Array): 数组是一个存储在相同类型的固定大小的顺序的集合,书序是用来存储数据的集合,通常认为数组是一个同一个人类型的变量集合,所有数组都是由连续的的内存地址位置构成,最低的地址对应的是第一个元素,最高的对应最后一个元素。声明数组语法格式:  datatype[] arrname;

 声明一个数组并不会初始化,当初始化数组变量的时候,可以给数组赋值。   数组是一个引用类型。所以使用关键字new 来常见数组的实例。

   double [] balance=new double[12];

   数组的初始化还可以这样写。  一边初始化一边进行赋值    int [] marks=new int[34] {23,24,34545,5656,5756,}; 这样的话还可以省略数组的大小声明。

  数组的访问:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            bool numbersOk = false;
            double var1, var2;
            var1 = 0;
            var2 = 0;
            while (!numbersOk) {
                Console.WriteLine("Give me a number");
                var1 = Convert.ToDouble(Console.ReadLine());
                Console.WriteLine("Give me second number");
                var2 = Convert.ToDouble(Console.ReadLine());

                if((var1>10)&&(var2>=10)){
                numbersOk=true;}
                else{
                if((var1<=10)&&(var2<=10)){
                numbersOk=true;}
                    else{
                        Console.WriteLine("one number may be great ");
                    }
                }
            }
            Console.WriteLine("your input numbers is {0},{1}",var1,var2);
            Console.WriteLine("you true or false is numberOK {0}", numbersOk);
            Console.ReadLine();
            Console.ReadKey();
            Test T = new Test();
            Console.WriteLine("下面进行的输入");
            T.Panduan();
            Shuzu S = new Shuzu();
            S.shuzu();
            StringTest St = new StringTest();
            St.ceshiString();
            Console.ReadKey();


        }
    }
    class   Test {
        public void Panduan() {
            String[] i={"ds","sfsdf"};
            if (i.Length != 2) {
                Console.WriteLine("Two argument requried");
                return;
            }
            string param1 = i[0];
            //int param2 = convert.toint32(i[1]);
            Console.WriteLine("String parameter {0}", param1);
            //console.writeline("string parameter {0}", param2);
            Console.ReadKey();
            Console.ReadLine();



        }
    }
    class Shuzu {
        public void shuzu() {
            int[] n = new int[10];
 
            //初始化数组 n的元素
            for (int i = 0; i < 10; i++) {
                n[i] = i + 100;
            }
            for (int j = 0; j < 10; j++)
            {
                Console.WriteLine("inputout number {0}", n[j]);
            }
            Console.ReadLine();
            foreach (int j in n) {
                int i = j - 100;
                Console.WriteLine("Elemnt{0}={1}",i,j);
            }
            Console.ReadKey();
        }
    }
    class Foreachtest {
    public void xunhuan(){

    }}
    class StringTest {
        public void ceshiString() {
            String fname;
            String laname;
            fname = "TianYa";
            laname = "ming";
            String fullName = fname + laname;
            Console.WriteLine("Full name is {0}", fullName);
            Console.ReadLine();
            char []letters = { 'w', 'e', 'W' };
            String greetings = new String(letters);
            Console.WriteLine("Greeting :{0",greetings);
            Console.ReadKey();
            //返回字符串
            String[] sarray = { "Hello", "Form" };
            String mesage = String.Join("", sarray);
            DateTime waitng = new DateTime(2012, 12, 12, 17, 12, 45);
            String hat = String.Format("message sent at {0}", waitng);
            Console.ReadKey();
        }
    }
}
5、String类的方法

    public staticint Compare(String strA,Sttring strB)  比较两个制定的String对象,并返回一个表示他排列书序中的相对位置。该方法区分大小写。

   public static Compare(String strA,Strign strB,bool ignoreCase) 比较两个指定对象的,,并返回表示一个在排列的顺序中的相对位置整数。次方法忽略大小写

    public static Concat(String A,String B)  连接两个对象

  public  static String Comcat(Sting A,String B,String C) 连接三个对象

public bool Contains( string value )
返回一个表示指定 string 对象是否出现在字符串中的值。
7 public static string Copy( string str )
创建一个与指定字符串具有相同值的新的 String 对象。
8 public void CopyTo( int sourceIndex, char[] destination, int destinationIndex, int count )
从 string 对象的指定位置开始复制指定数量的字符到 Unicode 字符数组中的指定位置。
9 public bool EndsWith( string value )
判断 string 对象的结尾是否匹配指定的字符串。
10 public bool Equals( string value )
判断当前的 string 对象是否与指定的 string 对象具有相同的值。
11 public static bool Equals( string a, string b )
判断两个指定的 string 对象是否具有相同的值。
12 public static string Format( string format, Object arg0 )
把指定字符串中一个或多个格式项替换为指定对象的字符串表示形式。
13 public int IndexOf( char value )
返回指定 Unicode 字符在当前字符串中第一次出现的索引,索引从 0 开始。
14 public int IndexOf( string value )
返回指定字符串在该实例中第一次出现的索引,索引从 0 开始。
15 public int IndexOf( char value, int startIndex )
返回指定 Unicode 字符从该字符串中指定字符位置开始搜索第一次出现的索引,索引从 0 开始。
16 public int IndexOf( string value, int startIndex )
返回指定字符串从该实例中指定字符位置开始搜索第一次出现的索引,索引从 0 开始。
17 public int IndexOfAny( char[] anyOf )
返回某一个指定的 Unicode 字符数组中任意字符在该实例中第一次出现的索引,索引从 0 开始。
18 public int IndexOfAny( char[] anyOf, int startIndex )
返回某一个指定的 Unicode 字符数组中任意字符从该实例中指定字符位置开始搜索第一次出现的索引,索引从 0 开始。
19 public string Insert( int startIndex, string value )
返回一个新的字符串,其中,指定的字符串被插入在当前 string 对象的指定索引位置。
20 public static bool IsNullOrEmpty( string value )
指示指定的字符串是否为 null 或者是否为一个空的字符串。
21 public static string Join( string separator, string[] value )
连接一个字符串数组中的所有元素,使用指定的分隔符分隔每个元素。
22 public static string Join( string separator, string[] value, int startIndex, int count )
连接接一个字符串数组中的指定位置开始的指定元素,使用指定的分隔符分隔每个元素。
23 public int LastIndexOf( char value )
返回指定 Unicode 字符在当前 string 对象中最后一次出现的索引位置,索引从 0 开始。
24 public int LastIndexOf( string value )
返回指定字符串在当前 string 对象中最后一次出现的索引位置,索引从 0 开始。
25 public string Remove( int startIndex )
移除当前实例中的所有字符,从指定位置开始,一直到最后一个位置为止,并返回字符串。
26 public string Remove( int startIndex, int count )
从当前字符串的指定位置开始移除指定数量的字符,并返回字符串。
27 public string Replace( char oldChar, char newChar )
把当前 string 对象中,所有指定的 Unicode 字符替换为另一个指定的 Unicode 字符,并返回新的字符串。
28 public string Replace( string oldValue, string newValue )
把当前 string 对象中,所有指定的字符串替换为另一个指定的字符串,并返回新的字符串。
29 public string[] Split( params char[] separator )
返回一个字符串数组,包含当前的 string 对象中的子字符串,子字符串是使用指定的 Unicode 字符数组中的元素进行分隔的。
30 public string[] Split( char[] separator, int count )
返回一个字符串数组,包含当前的 string 对象中的子字符串,子字符串是使用指定的 Unicode 字符数组中的元素进行分隔的。int 参数指定要返回的子字符串的最大数目。
31 public bool StartsWith( string value )
判断字符串实例的开头是否匹配指定的字符串。
32 public char[] ToCharArray()
返回一个带有当前 string 对象中所有字符的 Unicode 字符数组。
33 public char[] ToCharArray( int startIndex, int length )
返回一个带有当前 string 对象中所有字符的 Unicode 字符数组,从指定的索引开始,直到指定的长度为止。
34 public string ToLower()
把字符串转换为小写并返回。
35 public string ToUpper()
把字符串转换为大写并返回。
36 public string Trim()
移除当前 String 对象中的所有前导空白字符和后置空白字符。

的风格大方

原文地址:https://www.cnblogs.com/xinxianquan/p/9682098.html