字符转ASCII报错
发表在C#答疑区
2017-09-25
悬赏:5 学分
是否精华
是
否
版块置顶:
是
否
尊敬的老师:
上午好
我照着网上的文章,一模一样的写了段字符转ASCII的代码,报了2个错误,不明白是啥意思,以及该如何改正呢?
这是我写的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
//字符转ASCII
public class STRasc
{
public static int Asc(string character)
{
if (character.length == 1)
{
System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
int intAsciiCode = (int)ASCIIEncoding.GetBytes(character)[0];
return (intAsciiCode);
}
else
{
throw new Exception("character is not valid");
}
}
}以下是报错以及网上原版的截图:


于2017-09-25 10:19:51编辑
首页上一页 1 下一页尾页 3 条记录 1/1页

购物车
发表新帖
立即签到
已解决







