c# - 变量变化荒谬,如 3 到 51?
问题描述
我一直在尝试解决代码战问题,但是当我使用 Math.Pow 时,我得到了有趣的结果。
就像我输入 3 作为基础和 3 作为功率但结果
我知道我应该使用 double 但 int 在其他项目中可以正常工作:D
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
int value = 371;
int cL;
List<int> NumberList = new List<int>();
string Sayı = value.ToString(); //to make value to string so I could
int L = Sayı.Length; // count length and putto array
char[] charArray = Sayı.ToCharArray();
foreach(char chr in charArray) // getting digits multiply with himself for L times
{
cL = chr; // chr İS 3 BUT WHEN ASSİGNED TO cL İT CHANGES TO 51
Console.WriteLine(chr) // gives 3
Console.WriteLine(cL) // gives 51
double nmbr = Math.Pow(cL, L); // calculating power etc
int charr = (int) nmbr; // assign result to int
NumberList.Add(charr); // take assigned int to list
}
解决方案
字符有代码,您的字符 3 的值为 51。有关所有字符的列表,请参见此处:
推荐阅读
- c# - 返回基本类型时从继承中获取值
- python - 通过 python-docx 转录 .docx 文件以修改字体和字体大小。需要重建目标文件中的段落
- python - 使用 Python 从 HTML 源代码中提取 .jpg
- ios - 声明 NotificationCenter.default.addObserver [swift]
- json - JSON array within an object is not being parsed
- vba - 选择 Word 文档的开头
- angular - 检测Angular 8中不同输入的焦点丢失?
- bash - Ping 子网但使用 bash 跳过范围内的一些 IP
- javascript - 在数组中查找具有特定属性的项目,然后计算有多少,然后使用相应结果的对象创建新数组
- angular - 滚动时,mat-autocomplete 选项下拉菜单不会粘住