日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

c#每日小结 七

發布時間:2024/4/14 C# 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c#每日小结 七 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

擴展方法:必須是static,但是調用的時候像調用普通方法一樣調用;

例:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using ExterString;//加入引用空間

?

namespace 擴展方法

{

??? class Program

??? {

??????? static void Main(string[] args)

??????? {

??????????? string s = "abbba";

?

??????????? foreach (int i in s.IndexOfAll("a"))

??????????? {

???????? ???????Console.Write(i+"??? ");

??????????? }

?

?

??????? }

??? }

}

//定義擴展方法

namespace ExterString

{

??? static class Exterlp

??? {

??????? public static int[] IndexOfAll(this string str, string s)//注意前面的static,括號中的參數

??????? {

??????????? char[] ch = new char[str.Length];

??????????? int[] aindex = new int[str.Length];

??????????? int count = 0;

??????????? for (int i = 0; i < str.Length; i++)

??????????? {

??????????????? aindex[i] = -1;

??????????? }

?

??????????? str.CopyTo(0, ch, 0, str.Length);

?????? ?????for (int i = 0; i < str.Length; i++)

??????????? {

??????????????? if (ch[i].ToString() == s)

??????????????? {

??????????????????? for (int j = 0; j < str.Length; j++)

??????????????????? {

??????????????????????? if (aindex[j] == -1)

?????????????? ?????????{

??????????????????????????? aindex[j] = i;

??????????????????????????? count++;

??????????????????????????? break;

??????????????????????? }

??????????????????? }

??????????????? }

??????????? }

??????????? int[] index = new int[count];

??????? ????for (int j = 0; j < str.Length; j++)

??????????? {

??????????????? if (aindex[j] != -1)

??????????????? {

??????????????????? for (int i = 0; i < count; i++)

??????????????????? {

??????????????????????? index[i] = aindex[j];

??????????????????????? break;

??????????????????? }

??????????????? }

?

??????????? }

??????????? return index;

?

??????? }

??? }

}

匿名方法:沒有方法簽名,與委托配合使用;由于不必創建單獨的方法,減少了實例化委托所需的代碼系統開銷;

例:this.load +=delegate{string s=”?? ”};

命名參數:可以按形參名稱賦值;

注意:如果使用匿名參數,必需所有的參數都命名;

例:

static void Main(string[] args)

??????? {

??????????? ss(name: "gxr", weight: 45.0, age: 20);

?

?

? static void ss(string name,int age,double weight)

??????? {

??????????? Console.WriteLine(name+age+weight);

??????? }

?

?

可選 參數:

注意:形參列表的末尾定義,必須放在必需形參(普通參數 ,區別于可選參數)之后;方法,構造函數,索引器,委托的定義可以指明其形參是必需的還是可選 的;任何調用都必須為必需的形參提供實參,可以省略可選形參的實參;

例:

static void Main(string[] args)

??????? {

??????????? ss("gxrrrr");

static void ss(string name, int age = 20, double weight = 456)

??????? {

??????????? Console.WriteLine("{0},{1},{2}", name, age, weight);

??????? }

?

轉載于:https://blog.51cto.com/3298646/617854

總結

以上是生活随笔為你收集整理的c#每日小结 七的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。