这是我打印乘法表的C#代码
using System;
namespace MultiplicationTable
{
class Program
{
static void Main(string[] args)
{
dynamic value;
int i;
value = "123456789";
int num = Convert.ToInt32(Console.ReadLine());
foreach (char name in value)
{
i = Convert.ToInt32(name);
Console.WriteLine("{0} x {1} = {2}",i,num,i*num);
}
Console.ReadKey();
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行的程序的值我从开始49.输入6的输出如下

Bol*_*ock 12
数字1的Unicode代码点为49 Convert.ToInt32()具有char参数返回所述自变量的代码点.
如果您的乘法值必须在字符串中,则快速解决此问题是在转换为int之前将每个数字转换为字符串:
i = Convert.ToInt32(name.ToString());
Run Code Online (Sandbox Code Playgroud)
但是如果你在一系列数字上进行乘法运算,那么你可能更适合使用int数组.如果您正在计算数字,则没有理由将它们存储在字符串中.