1 BigInteger
BigInteger is a new class in the Net4.0 System.numerics namespace that represents a signed integer of any size. These all have minvalue and MaxValue attributes, such as the Int32,int64 in previous versions, which means that there is a size limit, and BigInteger no size limit, So in theory, when large numbers are large enough, outofmemoryexception anomalies may occur.
As an example of BigInteger, the following example is a function that computes the Fibonacci:
public static int Fibonacci (int x)
{
var prevalue =-1;
var curvalue = 1;
for (int i = 0; I <= x; ++i)
{
var sum = prevalue + curvalue;
Prevalue = Curvalue;
Curvalue = sum;
}
return curvalue;
}
The above code overflows when the value of X is 47, and the result is the following figure:
Now modify the code and use the BigInteger code as follows:
public static BigInteger Fibonacci (int x)
{
var prevalue = new BigInteger ( -1);
var curvalue = new BigInteger (1);
for (int i = 0; I <= x; ++i)
{
var sum = prevalue + curvalue;
Prevalue = Curvalue;
Curvalue = sum;
}
return curvalue;
}
Assign the X to 47 again, and run the result as shown below:
2 Complex
Complex Tong BigInteger is also under the System.numerics namespace. Simply put, a class that computes a complex number. Look at the example below
private static void Complexdemo ()
{
var z1 = new Complex (3, 4);
var z2 = new Complex (5, 6);
var r1 = Complex.add (z1, Z2);
var r2 = complex.subtract (z1, Z2);
var r3 = complex.multiply (z1, Z2);
var r4 = complex.divide (z1, Z2);
Console.WriteLine ("Z1+Z2:" + R1);
Console.WriteLine ("Z1-Z2:" + R2);
Console.WriteLine ("Z1*Z2:" + R3);
Console.WriteLine ("Z1/Z2:" + R4);
}
The results of the operation are shown below:
3 Tuple
Tuple can define a lot of complex information, and realize a variety of flexible format definitions.
Create a collection of single data types
var a = Tuple.create (2, 3, 4, 5);
var B = tuple.create ("oec2003", "oec2004", "oec2005");
Create a collection of complex types
public static Tuple<int, String, Uri, datetime> GetInfo ()
{return
tuple.create<int, string, Uri, Datetime> ("oec2003", New
Uri ("http://oec2003.cn"), DateTime.Now);
4 sortedset<t>
Sortedset<t> is a collection of stored data that can be sorted. A simple example is initialized to a unordered set of integers, and then the sequential output is ordered, as follows:
public static void Sortedsetdemo ()
{
int count = 0;
var Set1 = new Sortedset<int> () {1,5,3,9,4,6};
foreach (int i in Set1)
{
count++;
Console.Write (i);
if (Count!= Set1. Count) Console.Write (",");
}
}
In addition to sorting, you can also find a set of maximum, minimum and set scope of the set, see the following example:
public static void Sortedsetdemo ()
{
var set1 = new Sortedset<int> () {8, 5, 3, 9, 4, 6};
Console.WriteLine ("Mixvalue:" + Set1.) Min);
Console.WriteLine ("MaxValue:" + Set1.) MAX);
Console.Write ("subset:");
var subset = Set1. Getviewbetween (5, 9);
int count = 0;
foreach (int i in subset)
{
count++;
Console.Write (i);
if (Count!= subset.count) Console.Write (",");
}
}