我需要一个更快的方法来从子数组中找到最大的double值.
这是我现在这样做的方式:
static double FindMax(double[] x, int startIndex, int endIndex)
{
int i = startIndex;
double max = x[i++];
double value;
while(i <= endIndex)
{
value = x[i++];
if (value > max) max = value;
}
return max;
}
Run Code Online (Sandbox Code Playgroud)
但它有点慢.我需要一个更快的方法.有小费吗?
我是XAML的新手。我想知道所有x:和:x都是关于什么的。关于XAML的教程没有对此进行解释(或者我还没有足够了解)。
例如:
<Window x:Class="WpfTutorialSamples.WPF_Application.ResourceSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="ResourceSample" Height="150" Width="350">
<Window.Resources>
<sys:String x:Key="strHelloWorld">Hello, world!</sys:String>
</Window.Resources>
<StackPanel Margin="10">
<TextBlock Text="{StaticResource strHelloWorld}" FontSize="56" />
<TextBlock>Just another "<TextBlock Text="{StaticResource strHelloWorld}" />" example, but with resources!</TextBlock>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
x在这些行中是什么意思?
我想打印精度比默认值更高的浮点数.
例如,当我从浮点数打印PI的值时,我得到6位小数.但是如果我将浮点数中的相同值复制到一个双精度数并打印出来,我得到14位小数.
为什么在打印相同的值时会获得更高的精度但是为双倍?
如何在打印浮点数时让Console.WriteLine()输出更多小数,而不需要先将其复制到双精度数中?
我也尝试了0.0000000000,但它没有更精确的写入,它只是添加了更多的零.: - /
我的测试代码:
float x = (float)Math.PI;
double xx = x;
Console.WriteLine(x);
Console.WriteLine(xx);
Console.WriteLine($"{x,18:0.0000000000}"); // Try to force more precision
Console.WriteLine($"{xx,18:0.0000000000}");
Run Code Online (Sandbox Code Playgroud)
输出:
3,141593
3,14159274101257
3,1415930000 <-- The program just added more zeroes :-(
3,1415927410
Run Code Online (Sandbox Code Playgroud)
我还尝试在https://www.h-schmidt.net/FloatConverter/IEEE754.html上输入PI
PI的二进制浮点表示为0b01000000010010010000111111011011
所以该值为:2*0b1.10010010000111111011011 = 2*1.57079637050628662109375 = 3.1415927410125732421875
所以有更多的小数要输出.如何让C#输出这个整数值?
是否可以为EnumConverter始终使用而不是默认值的枚举类型编写自定义EnumConverter?
我希望在我的 XAML 代码中随处使用此转换器,而无需指定要使用的转换器(如果可能)