Note that CLR objects have max size limit of 2GB and if you cross it you get
OutOfMemoryException
.
String
objects consume approximately the following:
20 bytes for the object + 2 bytes per character for the object's inner buffer
So you would need (note that I presume your PI text file is ASCII encoded):
20 + 2 * 1.5GB
However nowadays there is actually a way to make such a big string, in .NET 4.5 a
gcAllowVeryLargeObjects
feature was introduced.
But nevertheless by passing the default limit you just know that it will not run smoothly at all, the users experience will be terrible.
So as an alternative how about you paginate its content, in other words how about you display just a part of its content, let's say 10k chars, and allow user to move 10kB back and 10kB forward.
For example something like this:
Dim piFile As String = "C:\PI.txt"
Dim piTextPartSize As Integer = 10000
Dim piTextPart As String
Dim piPartIndex As Integer = 0
Using piReader = New StreamReader(piFile)
Dim piPartCharacters As Char() = New Char(piTextPartSize - 1) {}
piReader.BaseStream.Position = piPartIndex * piTextPartSize
piReader.Read(piPartCharacters, 0, piTextPartSize)
piTextPart = New String(piPartCharacters)
End Using