string s = "I0035290K000"; int checksum = s.Select(x => (int)x).Sum();
转换I的ASSCLL值,0对应的ASCLL值依次类推,使他们的值相加
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string s = "I0033178K1000C"; int checkcode = s.Select(x => (int)x).Sum(); Console.WriteLine(checkcode); } } }
int checksum = s.Select(x => (int)x).Sum();
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s = "I0033178K1000C";
int checkcode = s.Select(x => (int)x).Sum();
Console.WriteLine(checkcode);
}
}
}
{
string restring = textBox1.Text;
char[] by = restring.ToCharArray(); int bcc = 0;
for (int i = 0; i < by.Length; i++)
{
bcc += (int)by[i]; bcc = bcc % 256; }
int result = Convert.ToInt32(bcc) ^ 135;
byte[] data = new byte[1];
data[0] = Convert.ToByte(result);
restring += ByteArrayToHexString(data);
textBox3.Text=restring; return restring.Trim(); }
一楼的是可以,但我自己写的这个你们看一下?我吧输入放到textbox1中,在textbox3中输出,你们给看一下
如果你使用C# 2.0或者1.0,你的代码就是我的代码的非LINQ等价形式。
这种方法最简单:先引用 System.Linq; string test = "I0033178K1000C";
int sum = test.Select(o => (int)o).Sum();
你们执行一下试试,我在控制台执行是可以的
满分你太强了