我找不到用于编码继承基类B(用C#编写)的类型D和除基类隐式构造函数之外的构造函数的正确语法:
C#代码:
public class B
{
private int _i;
private float _f;
public B()
{
_i = 0;
_f = 0.0f;
}
public B(int i)
{
_i = 0;
_f = 0.0f;
}
public B(int i, float f)
{
_i = i;
_f = f;
}
}
Run Code Online (Sandbox Code Playgroud)
F#代码:
type D() =
inherit B()
//how to inherit from other constructors ?
Run Code Online (Sandbox Code Playgroud)
谢谢
我在这个网站上看到了一个StringBuilder代码示例,说明了AppendFormat用法:
using System;
using System.Text;
class Program
{
static int[] _v = new int[]
{
1,
4,
6
};
static void Main()
{
StringBuilder b = new StringBuilder();
foreach (int v in _v)
{
b.AppendFormat("int: {0:0.0}{1}", v,
Environment.NewLine);
}
Console.WriteLine(b.ToString());
}
}
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)=== Output of the program === int: 1.0 int: 4.0 int: 6.0
我在哪里可以找到有关字符串格式的高级规则的文档?
我正在尝试以下F#等效:
[C#]
public virtual int Property { get; set; }
Run Code Online (Sandbox Code Playgroud)
但是这段代码(以及许多其他组合)不起作用:
[F#]
abstract member Id: int with get, set
default val this.Id = 123 with get, set
Run Code Online (Sandbox Code Playgroud) 是否有可能在输出中获取发生错误的列号(主要来自cl.exe)MSBuild.exe?
我想在Sublime Text上正确绑定F4键.
Microsoft (R) Build Engine version 4.0.30319.17929
[Microsoft .NET Framework, version 4.0.30319.17929]
Copyright (C) Microsoft Corporation. All rights reserved.
'Microsoft Visual C++ Compiler Nov 2012 CTP' is for testing purposes only.
Mesh.cpp
..\..\..\lib\Kernel\Mesh.cpp(94): error C2143: syntax error : missing ';' before 'return' [C:\Users\Stringer\Code\XXXXXXX\kernel\lib\Kernel\kernel.vcxproj]
[Finished in 1.4s]
Run Code Online (Sandbox Code Playgroud) 是否可以实现可变参数模板类的函数成员,该函数成员从可变参数列表返回给定类型的索引.
我看到的问题是创建一些假的可变参数列表,只是为了触发编译时模板评估.
template<typename... TArgs>
class Foo
{
template<typename T, typename TArg>
int _get_idx(int i, const TArg &curr, TArgs...args)
{
if (std::is_same(T, TArg)) {
return i;
}
else {
return get_id(i+1, args...);
}
}
Run Code Online (Sandbox Code Playgroud)
用法如下:
Foo<A, B, C> foo;
int i = foo.get_idx<B>(); // i == 1
Run Code Online (Sandbox Code Playgroud) 查看由cargo(cargo build --release)生成的二进制代码。我在二进制文件中发现SSSE3使用了类似的指令pshufb 。
看着CFG我有:
$ rustc --print cfg
debug_assertions
target_arch="x86_64"
target_endian="little"
target_env=""
target_family="unix"
target_feature="fxsr"
target_feature="sse"
target_feature="sse2"
target_feature="sse3"
target_feature="ssse3"
target_os="macos"
target_pointer_width="64"
target_vendor="apple"
unix
Run Code Online (Sandbox Code Playgroud)
给定SIMD ISA(AVX2或SSSE3)时,我有不同的路径,并且期望具有默认构建的非SIMD路径。
#[cfg(target_feature = "avx2")]
{
...
return;
}
#[cfg(target_feature = "ssse3")]
{
...
return;
}
// portable Rust code at the end
...
Run Code Online (Sandbox Code Playgroud)
这是否意味着默认发布版本将始终使用多达SSSE3指令,而不仅仅是在x86_64上强制使用的SSE2?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
var x = Environment.GetResourceString("test"); //compile-time error
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误是:'System.Environment'不包含'GetResourceString'的定义.
编辑:OP表示他正在使用Compact Framework,v3.5.
我不明白,我的代码出了什么问题?谢谢!
使用fsi.exe启动.fsx时,代码是在调试或发布模式下以交互方式编译的吗?
因为我做了fsi.exe --debug test.fsx,它仍然打印"发布".
test.fsx:
...
#if DEBUG
do printf "debug"
#else
do printf "release"
#endif
...
Run Code Online (Sandbox Code Playgroud)
我错过了什么?谢谢!
在C#中,我可以:
var n = new Person()
{
FirstName = "John",
LastName = "Smith"
};
Run Code Online (Sandbox Code Playgroud)
我可以在F#中做同样的事情吗?我的意思是,创建一个类并指定一些属性.