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);
}
}
}
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);
}
}
}
相关文章推荐
- C#自定义List类
- C#获取文件和文件夹大小
- C#Equal的使用
- C# winform带进度条的图片下载
- C#委托的详细使用
- C#控制台吹泡泡算法
- C#使用checked关键字处理"溢出"错误
- C#冒泡泡算法
- C#用注册表开机自动启动某某软件
- C#递归算法详解
- C#工厂模式代码实例
- C#获取时间戳的方法
- C#通过反射进行枚举描述相关操作
- C#获取北京时间与设置系统时间
- C#正则表达式匹配字符串
- C#联机获取公网IP
- C#在Dictionary中使用枚举作为键
- C# 字典 Dictionary 遍历
- C# 对文本文件的几种读写方法总结
- ``` > **c#学习(一)** ```