1
2const b64string = /* whatever */;
3const buf = Buffer.from(b64string, 'base64');
4
1class Program
2{
3 static void Main(string[] args)
4 {
5 var account = new ExternalAccount() { Name = "Someone" };
6 string json = JsonConvert.SerializeObject(account);
7 string base64EncodedExternalAccount = Convert.ToBase64String(Encoding.UTF8.GetBytes(json));
8 byte[] byteArray = Convert.FromBase64String(base64EncodedExternalAccount);
9
10 string jsonBack = Encoding.UTF8.GetString(byteArray);
11 var accountBack = JsonConvert.DeserializeObject<ExternalAccount>(jsonBack);
12 Console.WriteLine(accountBack.Name);
13 Console.ReadLine();
14 }
15}
16
17[Serializable]
18public class ExternalAccount
19{
20 public string Name { get; set; }
21}
1ulong ulNumber = 163245617943825;
2try {
3 long number1 = (long) ulNumber;
4 Console.WriteLine(number1);
5}
6catch (OverflowException) {
7 Console.WriteLine("{0} is out of range of an Int64.", ulNumber);
8}
9
10double dbl2 = 35901.997;
11try {
12 long number2 = (long) dbl2;
13 Console.WriteLine(number2);
14}
15catch (OverflowException) {
16 Console.WriteLine("{0} is out of range of an Int64.", dbl2);
17}
18
19BigInteger bigNumber = (BigInteger) 1.63201978555e30;
20try {
21 long number3 = (long) bigNumber;
22 Console.WriteLine(number3);
23}
24catch (OverflowException) {
25 Console.WriteLine("{0} is out of range of an Int64.", bigNumber);
26}
27// The example displays the following output:
28// 163245617943825
29// 35902
30// 1,632,019,785,549,999,969,612,091,883,520 is out of range of an Int64.
31
1decimal[] values= { Decimal.MinValue, -1034.23m, -12m, 0m, 147m,
2 199.55m, 9214.16m, Decimal.MaxValue };
3long result;
4
5foreach (decimal value in values)
6{
7 try {
8 result = Convert.ToInt64(value);
9 Console.WriteLine("Converted the {0} value '{1}' to the {2} value {3}.",
10 value.GetType().Name, value,
11 result.GetType().Name, result);
12 }
13 catch (OverflowException) {
14 Console.WriteLine("{0} is outside the range of the Int64 type.",
15 value);
16 }
17}
18// The example displays the following output:
19// -79228162514264337593543950335 is outside the range of the Int64 type.
20// Converted the Decimal value '-1034.23' to the Int64 value -1034.
21// Converted the Decimal value '-12' to the Int64 value -12.
22// Converted the Decimal value '0' to the Int64 value 0.
23// Converted the Decimal value '147' to the Int64 value 147.
24// Converted the Decimal value '199.55' to the Int64 value 200.
25// Converted the Decimal value '9214.16' to the Int64 value 9214.
26// 79228162514264337593543950335 is outside the range of the Int64 type.
27