日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
詳解.NET4.0Beta2的Complex和BigInteger類

本文將介紹的是.NET 4.0 Beta2中的Complex和BigInteger類,BigInteger類主要用途在于對不同數(shù)據(jù)的處理。希望對大家有所幫助。

成都創(chuàng)新互聯(lián)自成立以來,一直致力于為企業(yè)提供從網(wǎng)站策劃、網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè)、網(wǎng)站制作、電子商務(wù)、網(wǎng)站推廣、網(wǎng)站優(yōu)化到為企業(yè)提供個性化軟件開發(fā)等基于互聯(lián)網(wǎng)的全面整合營銷服務(wù)。公司擁有豐富的網(wǎng)站建設(shè)和互聯(lián)網(wǎng)應(yīng)用系統(tǒng)開發(fā)管理經(jīng)驗、成熟的應(yīng)用系統(tǒng)解決方案、優(yōu)秀的網(wǎng)站開發(fā)工程師團隊及專業(yè)的網(wǎng)站設(shè)計師團隊。

.NET4.0 Beta2中提供了新的System.Numerics命名空間,對應(yīng)于System.Numerics.dll。該命名空間下就兩個類BigInteger和Complex,我們來簡單了解下這兩個類的用法。

BigInteger:任意大小的帶符號整數(shù)

1.Int64, SByte, UInt16, UInt32, and UInt64這些都有一個MinValue和MaxValue屬性。而BigInteger沒有這兩個屬性,因為它沒有大小限制。2.不可變的類型.3.由于他沒有大小限制,理論上當(dāng)它足夠大的時候會出現(xiàn)OutOfMemoryException異常.

BigInteger類初始化

1.我們可以使用已有的數(shù)據(jù)類型來初始化BigInteger,如下:

 
 
 
  1. BigInteger bigIntFromDouble = new BigInteger(179032.6541);//會截取小點前的  
  2. BigInteger bigIntFromInt64 = new BigInteger(934157136952); 

2.我們也可以使用超出現(xiàn)有數(shù)據(jù)類型范圍的方式來得到BigInteger:

 
 
 
  1. byte[] bytes = { 5, 4, 3, 2, 1 };  
  2. BigInteger number = new BigInteger(bytes);  
  3. Console.WriteLine("The value of number is {0} (or 0x{0:x}).", number);   
  4. //The value of number is 4328719365 (or 0x102030405).    

字節(jié)數(shù)組的第一個元素為16進制的最低位,依次升高.3.可以使用Parse或 TryParse方法將string的實例化為BigInteger:

 
 
 
  1. string positiveString = "91389681247993671255432112000000";  
  2. string negativeString = "-90315837410896312071002088037140000";  
  3. BigInteger posBigInt = 0;  
  4. BigInteger negBigInt = 0;  
  5.  
  6. posBigInt = BigInteger.Parse(positiveString);  
  7. Console.WriteLine(posBigInt);  
  8.  
  9. BigInteger.TryParse(negativeString, out negBigInt);  
  10. Console.WriteLine(negBigInt); 

4. 還可以使用靜態(tài)方法Pow如下:

 
 
 
  1. BigInteger number = BigInteger.Pow(Int64.MaxValue, 3); 

BigInteger支持所有的數(shù)學(xué)運算,我們可以完全象使用其他整數(shù)類型一樣使用BigInteger

Complex復(fù)數(shù)類

 
 
 
  1. 1.var z1 = new Complex(); // this creates complex zero (0, 0)  
  2.   var z2 = new Complex(2, 4);  
  3.   var z3 = new Complex(3, 5);  
  4.  
  5.   Console.WriteLine("Complex zero: " + z1);  
  6.   Console.WriteLine(z2 + " + " + z3 + " = " + (z2 + z3));  
  7.  
  8.   Console.WriteLine("|z2| = " + z2.Magnitude);  
  9.   Console.WriteLine("Phase of z2 = " + z2.Phase); 

2.我們可以使用一個ComplexFormatter類來輔助我們做格式化輸出,如下:

 
 
 
  1. using System;  
  2. using System.Numerics;  
  3.  
  4. public class ComplexFormatter :IFormatProvider, ICustomFormatter  
  5. {  
  6.    public object GetFormat(Type formatType)   
  7.    {     
  8.       if (formatType == typeof(ICustomFormatter))  
  9.          return this;  
  10.       else 
  11.          return null;  
  12.    }  
  13.  
  14.    public string Format(string format, object arg,   
  15.                         IFormatProvider provider)  
  16.    {  
  17.       if (arg is Complex)  
  18.       {  
  19.          Complex c1 = (Complex) arg;   
  20.          // Check if the format string has a precision specifier.  
  21.          int precision;  
  22.          string fmtString = String.Empty;  
  23.          if (format.Length > 1) {  
  24.             try {  
  25.                precision = Int32.Parse(format.Substring(1));  
  26.             }  
  27.             catch (FormatException) {  
  28.                precision = 0;  
  29.             }  
  30.             fmtString = "N" + precision.ToString();  
  31.          }  
  32.          if (format.Substring(0, 1).Equals("I", StringComparison.OrdinalIgnoreCase))  
  33.             return c1.Real.ToString("N2") + " + " + c1.Imaginary.ToString("N2") + "i";  
  34.          else if (format.Substring(0, 1).Equals("J", StringComparison.OrdinalIgnoreCase))  
  35.             return c1.Real.ToString("N2") + " + " + c1.Imaginary.ToString("N2") + "j";  
  36.          else 
  37.             return c1.ToString(format, provider);  
  38.       }  
  39.       else 
  40.       {  
  41.          if (arg is IFormattable)  
  42.             return ((IFormattable) arg).ToString(format, provider);  
  43.          else if (arg != null)   
  44.             return arg.ToString();  
  45.          else 
  46.             return String.Empty;  
  47.       }                          
  48.    }  

3.使用如下:

 
 
 
  1. Complex c1 = new Complex(12.1, 15.4);  
  2. Console.WriteLine("Formatting with ToString():" + c1.ToString());  
  3. Console.WriteLine("Formatting with ToString(format): " +  c1.ToString("N2"));  
  4. Console.WriteLine("Custom formatting with I0:" +  String.Format(new ComplexFormatter(), "{0:I0}", c1));  
  5. Console.WriteLine("Custom formatting with J3:" +  String.Format(new ComplexFormatter(), "{0:J3}", c1)); 

文章標(biāo)題:詳解.NET4.0Beta2的Complex和BigInteger類
路徑分享:http://m.5511xx.com/article/djhsgsg.html