using System;
using System.Collections;
using System.Collections.Generic;
namespace Csharp
{
class Program
{
static void Main(string[] args)
{
/*
* 空合并运算符(??):
* 如果第一个操作数不是null,整个表达式就等于第一个操作数的值
* 如果第一个操作数是null,整个表达式就等于第二个操作数的值
*/
int? a = null;
int b;
b = a ?? 10;//b has the value 10
a = 3;
b = a ?? 10;//b has the value 3
Console.WriteLine(a);
Console.WriteLine(b);
Console.ReadKey();
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
namespace Csharp
{
class Program
{
static void Main(string[] args)
{
/*
* Parse()的用法
*/
string s = "100";
int i = int.Parse(s);
Console.WriteLine(i+50);
Console.ReadKey();
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
namespace Csharp
{
class Program
{
static void Main(string[] args)
{
int myIntNumber = 20;
object myObject = myIntNumber; //Box the int
int mySecondNumber = (int)myObject; //Unbox it back into an int
Console.WriteLine(mySecondNumber);
Console.ReadKey();
}
}
}