我需要一个具有BigInteger类型的构造函数的类.我想用这个代码将默认值设置为0,但是我遇到了编译错误.
public class Hello
{
BigInteger X {get; set;}
public Hello(BigInteger x = 0)
{
X = x;
}
}
public class MyClass
{
public static void RunSnippet()
{
var h = new Hello(); // Error <--
Run Code Online (Sandbox Code Playgroud)
怎么了?有没有办法将默认值设置为BigInteger参数?
我试图运行Python/cminus示例.从http://pypi.python.org/pypi/stringtemplate3/3.1,我为python安装了stringtemplate3 sudo python setup.py install.
当我运行以此代码开头的cminus.py时.
import sys
import antlr3
import stringtemplate3
Run Code Online (Sandbox Code Playgroud)
我有错误.
Traceback (most recent call last):
File "cminus.py", line 3, in <module>
import stringtemplate3
File "/Library/Python/2.7/site-packages/stringtemplate3/__init__.py", line 14, in <module>
from stringtemplate3.templates import *
File "/Library/Python/2.7/site-packages/stringtemplate3/templates.py", line 35, in <module>
import antlr
ImportError: No module named antlr
Run Code Online (Sandbox Code Playgroud)
看起来stringtemplate3使用的是antlr而不是antlr3.
我该如何解决这个问题?
我有这个代码,乘以32位*32位.
public static void RunSnippet()
{
System.Int32 x, y;
System.Int64 z;
System.Random rand = new System.Random(DateTime.Now.Millisecond);
for (int i = 0; i < 6; i++)
{
x = rand.Next(int.MinValue, int.MaxValue);
y = rand.Next(int.MinValue, int.MaxValue);
z = (x * y);
Console.WriteLine("{0} * {1} = {2}", x, y, z);
}
Run Code Online (Sandbox Code Playgroud)
但是,结果并不完全符合我的预期.

这有什么问题?
我有一个基类Base,以及继承它的A/B类.
public class Base
{
int x;
}
public class A : Base
{
int y;
}
public class B : Base
{
int z;
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用OfType来过滤我需要的唯一对象,如下所示:
public static void RunSnippet()
{
Base xbase; A a; B b;
IEnumerable<Base> list = new List<Base>() {xbase, a, b};
Base f = list.OfType<A>; // I need to get only the object A
Console.WriteLine(f);
}
Run Code Online (Sandbox Code Playgroud)
当我编译代码时,我收到此错误:
错误CS0428:无法将方法组'OfType'转换为非委托类型'Base'.你打算调用这个方法吗?
代码有什么问题?
我需要使用不同的工作区运行多个 eclipse。对于 Mac,我可以使用open -a Eclipse.app --args -data WORKSPACE. 当我执行时open -a Eclipse.app --args -data DIFFERENT_WORKSPACE,我只是重定向到现有的日食。
我正在尝试使用一种方法设置一个unique_ptr的映射。
class A {
map<int, unique_ptr<B>> x;
public:
void setx(const map<int, unique_ptr<B>>& x) {this->x = x;} // <-- error
...
};
Run Code Online (Sandbox Code Playgroud)
但是,我得到了这个错误。
'constexpr std::pair<_T1, _T2>::pair(const std::pair<_T1, _T2>&) [with _T1 = const int; _T2 = std::unique_ptr<ContextSummary>]' is implicitly deleted because the default definition would be ill-formed:
Run Code Online (Sandbox Code Playgroud)
这项作业有什么问题?
使用 python,我需要在迭代列表时动态添加列表中的成员:
i = [1,2,3,4,5]
for a in i:
if a == 1:
i.append(100)
print a
Run Code Online (Sandbox Code Playgroud)
能保证正常工作吗?
继有关解释:gen-class中的解剖学gen-class,我用leiningen得到的类文件.
leon new pinger 创建一个项目.cd src并在其中mkdir some创建了一个Example.clj文件.:aot [some.Example](或:aot :all)project.clj.Example.clj如下:
(ns some.Example
(:gen-class))
(defn -toString
[this]
"Hello, World!")
Run Code Online (Sandbox Code Playgroud)
然后我执行lein compile以获取target目录中的类.
然后,我正在执行此代码lein repl.
(-toString (some.Example.)) ; should return "Hello, World!"
Run Code Online (Sandbox Code Playgroud)
但是,我收到此错误消息.
CompilerException java.lang.RuntimeException: Unable to resolve symbol:
-toString in this context, compiling:(/private/var/folders/nw/dmb7jh3d2hq89296z2gnntqm0000gn/T/form-
init7145760420048735997.clj:1:1)
Run Code Online (Sandbox Code Playgroud)
.toString 工作良好.
user=> (.toString (some.Example.))
"Hello, World!"
Run Code Online (Sandbox Code Playgroud)
该网站解释说,我应该从两个相同的结果-toString和.toString,但我只能用正确的结果 …
我正在尝试在Graham Hutton的Haskell编程书(http://www.cs.nott.ac.uk/~gmh/book.html)中执行示例.尽管这些例子都是有文化的haskell,但我可以启动ghci来加载示例; 例如ghci cipher.lhs(http://www.cs.nott.ac.uk/~gmh/cipher.lhs):
GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( cipher.lhs, interpreted )
Ok, modules loaded: Main.
*Main> let2int 'a'
0
Run Code Online (Sandbox Code Playgroud)
但是有一些例子,由于ghci的变化,我有一些问题; 例如在第8章的Parsing.ls中,我有No instance for (Applicative ...)错误.
从https://ghc.haskell.org/trac/ghc/wiki/Migration/7.10我得到了一些提示,通过添加一些代码来消除一些错误.
> instance Applicative Parser where
> pure = return
> (<*>) = ap -- defined in Control.Monad
>
> instance Functor Parser where
> fmap = liftM
>
> instance Alternative Parser where
> (<|>) …Run Code Online (Sandbox Code Playgroud) 从Haskell中的Programming(http://www.cs.nott.ac.uk/~gmh/book.html)一书中,解析器定义如下:
> type Parser a = String -> [(a,String)]
Run Code Online (Sandbox Code Playgroud)
但是,从示例代码(http://www.cs.nott.ac.uk/~gmh/Parsing.lhs)中,定义略有不同.
> newtype Parser a = P (String -> [(a,String)])
Run Code Online (Sandbox Code Playgroud)
我发现了这个页面的不同之处:https://wiki.haskell.org/Type#Type_and_newtype如下:
type引入了类型的同义词,并使用相同的数据构造函数.newtype引入了类型的重命名,并要求您提供新的构造函数.
这是我的问题:
P(...)用于封装内容?