标签:取整 学习 font 部分 collect [] 联系 ble 表达式
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 表达式
{
class Program
{
static void Main(string[] args)
{
string myString="520";
int myint;
myint = (int)myString;
Console.WriteLine(myint);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 表达式
{
class Program
{
static void Main(string[] args)
{
int x;
float y=1.2f;
x = (int)y;
Console.WriteLine(x);
Console.ReadKey();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 表达式
{
class Program
{
static void Main(string[] args)
{
//double转换为int,使用Convert.ToInt32()
double myInt=1.6;
string myString = "123.45";
//string myString="abcd";
//string myString = "12345";
int intResult;
string stringResult;
intResult = (int)myInt;
Console.WriteLine(intResult);
Console.Read();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 表达式
{
class Program
{
static void Main(string[] args)
{
int myInt;
string myString = "123.45";
//string myString="abcd";
//string myString = "12345";
int intResult;
string stringResult;
intResult = Convert.ToInt32(myString);
Console.WriteLine(intResult);
Console.Read();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 表达式
{
class Program
{
static void Main(string[] args)
{
//double转换为int,使用Convert.ToInt32()
double myInt=1.6;
string myString = "123.45";
//string myString="abcd";
//string myString = "12345";
int intResult;
string stringResult;
intResult =Convert.ToInt32(myInt);
Console.WriteLine(intResult);
Console.Read();
}
}
}
//输出结果为2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 表达式
{
class Program
{
static void Main(string[] args)
{
int myInt;
//string myString = "123.45";
//string myString="abcd";
string myString = "12345";
int intResult;
string stringResult;
intResult = int.Parse(myString);
Console.WriteLine(intResult);
Console.Read();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 表达式
{
class Program
{
static void Main(string[] args)
{
//double转换为int,使用Convert.ToInt32()
double myInt=1.6;
string myString = "123.45";
//string myString="abcd";
//string myString = "12345";
int intResult;
string stringResult;
intResult = int.Parse(myInt);
Console.WriteLine(intResult);
Console.Read();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 表达式
{
class Program
{
static void Main(string[] args)
{
String myString = null;
String resultString;
int myInt;
// myInt = (int)myString;//不能转换null
myInt = Convert.ToInt32(myString);//将null转换为0
// myInt = int.Parse(myString);//不能转换null
Console.WriteLine(myInt);
Console.Read();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 表达式
{
class Program
{
static void Main(string[] args)
{
//强制括号转换只能转换数值类型的
int myInt = 3;
string stringResult;
stringResult=(string)myInt;
Console.Read();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 表达式
{
class Program
{
static void Main(string[] args)
{
//强制括号转换只能转换数值类型的
int myInt = 333;
string stringResult;
//stringResult = Convert.ToString(myInt);
stringResult = myInt.ToString();
Console.WriteLine(stringResult);
Console.Read();
}
}
}
C#中(int)、Conver.Toint32()、int.Parse()三种类型转换方式的区别与联系--C#基础知识
标签:取整 学习 font 部分 collect [] 联系 ble 表达式
原文地址:http://www.cnblogs.com/qikeyishu/p/7497581.html