User Id :    Password :      New Member   Forgot Password
 
BigInteger in C# 4.0
Description In C# 4.0 Microsoft has added so many features and I love all most all the features. In today’s post we are going to discuss BigInteger Class.   No. of Views     1153
  Rating     0
Author Jalpesh Vadgama   Posted On     18 Sep 2011
Tags ASP.NET 4.0    

Sample Code   Download Code

During programming some complex systems often we need a very big numbers. For example if we use some of asymmetrical cryptographic feature which require to use large numbers or we can give simple example of factorial where we sometime reached to limit of data type provided by C# compiler. At that time this BigInteger data type can be very handy. You can store 232 to 264 number in this data type. So its very big and you can copy very very big number in that data type.

So let’s take a simple example to write a factorial program. BigInteger data type comes under System.Numerics namespace. So first we have to add reference to our program to System.Numerics assembly like following.

Now we have added the reference to System.Numeric so we are ready for code. Here in code I have just taken a very large number in big integer which is out of range of integer to test out. So I have assigned ‘39242937852522522’ to big integer object and printed that. Following is a code for that.

using System; using System.Numerics;
namespace ExperimentConsole 
{    
class Program 
   {       
  static void Main(string[] args) 
     {            
            BigInteger n = 39242937852522522; 
            Console.WriteLine(n);    
     }   
   }
 }

Let’s run code and see output like following as expected its printing value.



If you are run same program with integer it will not compile. It will give ‘Can not covert type long to integer error’. That’s it. Hope you liked it. Stay tuned for more.. Till then happy programming. Namaste!!
 

 

About Author

About Author I am jalpesh vadgama an Microsoft MVP for Visual C# and BrainBench Certified ASP.NET Developer having more then 5 years of experience in .NET Technology.Please feel free to contact me for any queries via posting comments on my blog I will try to reply as early as possible. Please also visit my blog at http://jalpesh.blogspot.com/ Jalpesh Vadgama
No Photo
 
Country India
Company N/A
Home Page http://jalpesh.blogspot.com/

Rate this article

Rating options from poor, fair, good, very good to excelent.  
 

Comments

     
Write your comment here.  
Comment
Verification Code   
  
    
 
Section sponsored by