Solved

Storing really large numbers in C#

Posted on 2006-06-10
6
1,205 Views
Last Modified: 2008-01-09
I have this:

 this.button1.Text = DateTime.Now.Ticks.ToString();


which gives me numbers like:


632855413326400752


what I want to do is store this number, not in a text box, but in a variable whose type is large enough to store this value.


I don't know of any variable large enough to store this number.


What options do I have?
0
Comment
Question by:knowlton
6 Comments
 
LVL 5

Author Comment

by:knowlton
ID: 16878068
Also, i need an online reference for the C# data types and how large of values can each one hold:  int, long, double, word, etc.
0
 
LVL 5

Author Comment

by:knowlton
ID: 16878090
Huh, I guess a "long" does hold a number that big.
0
 
LVL 5

Accepted Solution

by:
aaronfeng earned 200 total points
ID: 16878112
Here is the link you want, just click on the data type you would to see more info about it:  http://msdn2.microsoft.com/en-us/ya5y69ds.aspx

You can use long to store that number, or use ulong to be safe because that number can't be negative anyways.

Cheers,

Aaron
http://geekswithblogs.net/afeng
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 10

Assisted Solution

by:_Katka_
_Katka_ earned 100 total points
ID: 16881447
Hi, just to make it clear:

long actualNow = DateTime.Now.Ticks;

because DateTime.Now.Ticks property is defined:

public long Ticks {get; }

regards,
Kate
0
 
LVL 5

Assisted Solution

by:t_itanium
t_itanium earned 100 total points
ID: 16884177
you can store it in a string variable....


or also you can do that in byte.
cheers
0
 
LVL 25

Assisted Solution

by:dstanley9
dstanley9 earned 100 total points
ID: 16885438
You could also use the BigInteger datatype from J#:

(from http://msdn.microsoft.com/msdnmag/issues/05/12/NETMatters/)

BigInteger i = new BigInteger(ulong.MaxValue.ToString());
BigInteger iSquared = i.multiply(i);
Console.WriteLine("i:\t" + i);
Console.WriteLine("i^2:\t" + iSquared);



i:      18446744073709551615
i^2:    340282366920938463426481119284349108225
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now