您的位置:首页 > 编程语言 > C#

C#Transfrom

2016-06-21 22:49 483 查看
代码如下:

private void btnConvertType_Click(object sender, EventArgs e)
{
if (rdo_btn_ConvertObject.Checked)//如果选择转换为object类型
{
using(FileStream filestram = new FileStream(@"d:\log.txt",System.IO.FileMode.Create))//创建文件文件流对象
{
object _object = filestram as object;//使用as关键字转换类型
if(_object != null)//判断转化是否成功
MessageBox.Show("转换为Object成功","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
else
MessageBox.Show("转换为Object未成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
if (rdo_btn_ConvertStream.Checked)//如果选择转换为Stream类型
{
using(FileStream filestream = new FileStream(@"d:\log.txt",System.IO.FileMode.Create))//创建文件流对象
{
object _object = filestream;
Stream _stream = _object as Stream;//使用as关键字转换类型
if (_stream != null)
MessageBox.Show("转换为Stream成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("转换为Stream未成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
if (rdo_btn_ConvertString.Checked)//如果选择转换为string类型
{
using (FileStream filestream = new FileStream(@"d:\log.txt",System.IO.FileMode.Create))//创建文件流
{
object _object = filestream;
string _string = _object as string;
if (_string != null)
MessageBox.Show("转换为String成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("转换为String未成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: