我正在将一个Delphi应用程序转换为C#,然后遇到了这个:
alength:=1; //alength is a byte
aa:=astring //astring is a string parameter passed into the function containing all this
alength:=strtoint(copy(aa,2,length(aa)-1));
所以,
copy
从现有字符串的一部分创建一个字符串,字符串的第一个字符从索引1
开始,而不是像其他语言一样从0
开始。它使用以下格式:
function copy ( Source : string; StartChar, Count : Integer ) : string;
然后是strtoint
,它将string
转换为int
。对于我在 c# 中转换的那段代码,我有:
alength = Convert.ToInt32(aa.Substring(1 ,aa.Length - 1));
这给了我错误:Error 131 Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)
。
由于alength
已经是字节类型,我认为我不需要强制转换它?