欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

C#數(shù)組和串操作有哪些

這篇文章主要介紹“C#數(shù)組和串操作有哪些”,在日常操作中,相信很多人在C#數(shù)組和串操作有哪些問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”C#數(shù)組和串操作有哪些”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!

站在用戶(hù)的角度思考問(wèn)題,與客戶(hù)深入溝通,找到崆峒網(wǎng)站設(shè)計(jì)與崆峒網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶(hù)體驗(yàn)好的作品,建站類(lèi)型包括:成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、主機(jī)域名、網(wǎng)頁(yè)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋崆峒地區(qū)。

關(guān)于C#數(shù)組和C#串操作:
1)串是由連續(xù)存儲(chǔ)的字符組成
2)C#中的串具有恒定不變的特性,即 一旦被創(chuàng)建,就不能改變長(zhǎng)度或者改變其中任何的字符。
3)串的連接、插入和刪除等操作都是生成了新串而沒(méi)有改變?cè)?br/>4)繼承自 System.object。所以是引用類(lèi)型(int,bool,char 等都是struct 不是class,是值類(lèi)型)。
5)System.String 是密封類(lèi),所以不能被繼承。
6)雖然System.String 是引用類(lèi)型,但C#中將String 看作是基元類(lèi)型,所以不用 new操作符創(chuàng)建實(shí)例,而是使用字符串駐留的機(jī)制。
7)System.String 繼承自 IComparable, ICloneable, IConvertible, IComparable, IEnumerable, IEnumerable, IEquatable
8)C#提供了StringBuilder類(lèi)型來(lái)支持高效地動(dòng)態(tài)創(chuàng)建字符串。

下面是自定義一個(gè)string類(lèi),類(lèi)中包含一個(gè)字段,用以存放字符序列的C#數(shù)組,還有一些常用的C#串操作。

public class StringDS  {  private char[] data;//char數(shù)組  //索引器  public char this[int index]  {  get   {  return data[index];  }  set  {  data[index] = value;  }  }  //構(gòu)造函數(shù)  public StringDS(char[] arr)  {  data = new char[arr.Length];  for (int i = 0; i < arr.Length; i++)  {  data[i] = arr[i];  }  }  //構(gòu)造函數(shù)   public StringDS(int len)  {  char[] arr = new char[len];  data = arr;  }  //求串長(zhǎng)   public int GetLength()  {  return data.Length;  }   //串比較   public int Compare(StringDS s)   {  int len=((this.GetLength()<=s.GetLength())?   this.GetLength():s.GetLength());   int i = 0;   for (i = 0; i < len; ++i)   {   if (this[i] != s[i])   {   break;   }   }   if (i <= len)  {  if (this[i] < s[i])  {  return -1;  }  else if (this[i] > s[i])  {  return 1;  }  }  else if (this.GetLength() == s.GetLength())  {  return 0;  }  else if (this.GetLength() < s.GetLength())  {  return -1;  }   return 1;  }   //求子串   public StringDS SubString(int index, int len)   {   if ((index<0) || (index>this.GetLength()-1) || (len<0) || (len>this.GetLength()-index))   {   Console.WriteLine("Position or Length is error!");   return null;   }    StringDS s = new StringDS(len);    for (int i = 0; i < len; ++i)   {   s[i] = this[i + index-1];   }    return s;   }   //串連接   public StringDS Concat(StringDS s)  {  StringDS s1 = new StringDS(this.GetLength() +s.GetLength());  for (int i = 0; i < this.GetLength(); ++i)  {  s1.data[i] = this[i];  }   for (int j = 0; j < s.GetLength(); ++j)  {  s1.data[this.GetLength() + j] = s[j];  }   return s1;  }   //串插入   public StringDS Insert(int index, StringDS s)   {   int len = s.GetLength();   int lenlen2 = len + this.GetLength();   StringDS s1 = new StringDS(len2);   if (index < 0 || index > this.GetLength() - 1)   {   Console.WriteLine("Position is error!");   return null;   }   for (int i = 0; i < index; ++i)   {   s1[i] = this[i];   }   for(int i = index; i < index + len ; ++i)   {   s1[i] = s[i - index];   }   for (int i = index + len; i < len2; ++i)   {   s1[i] = this[i - len];   }  return s1;  }  //串刪除   public StringDS Delete(int index, int len)  {  if ((index < 0) || (index > this.GetLength() - 1)  || (len < 0) || (len > this.GetLength() - index))  {  Console.WriteLine("Position or Length is error!");  return null;  }   StringDS s = new StringDS(this.GetLength() - len);   for (int i = 0; i < index; ++i)  {  s[i] = this[i];  }   for (int i = index + len; i < this.GetLength(); ++i)  {  s[i] = this[i];  }   return s;  }   //串定位   public int Index(StringDS s)   {   if (this.GetLength() < s.GetLength())   {   Console.WriteLine("There is not string s!");   return -1;   }      int i = 0;   int len = this.GetLength() - s.GetLength();   while (i < len)   {   if (this.Compare(s) == 0)   {  break;  }  }   if (i <= len)  {  return i;  }   return -1;  }   }

到此,關(guān)于“C#數(shù)組和串操作有哪些”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

本文標(biāo)題:C#數(shù)組和串操作有哪些
瀏覽路徑:http://www.chinadenli.net/article22/jdhpjc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站定制網(wǎng)站標(biāo)簽優(yōu)化網(wǎng)站維護(hù)做網(wǎng)站網(wǎng)站營(yíng)銷(xiāo)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)