在询问捕获'除以0'异常的过程中,我发现使用C++,我们不能这样做.我的意思是,除以0不会抛出std :: exception.
我发现的一些提示是我必须检查值,然后自己抛出异常.
我说它令人困惑,因为我认为C++采用了异常的想法,以便通过返回值方法来替换"旧的C/UNIX报告错误".
这是我的问题
我在没有'的clojure lib中定义命名空间,
(ns myproject.hello)
Run Code Online (Sandbox Code Playgroud)
但是,我使用'用于它.
(use 'myproject.hello)
Run Code Online (Sandbox Code Playgroud)
为什么是这样?这背后有什么逻辑吗?在gosh(方案的方言)中,我使用没有'ie(使用myproject)为什么这种不规则?
我安装了emacs C#模式.
.emacs文件如下
(require 'csharp-mode)
(setq auto-mode-alist
(append '(("\\.cs$" . csharp-mode)) auto-mode-alist))
(defun my-csharp-mode-fn ()
"function that runs when csharp-mode is initialized for a buffer."
(setq default-tab-width 4)
)
(add-hook 'csharp-mode-hook 'my-csharp-mode-fn t)
它工作得很好,但我看到块({..})与我的意图一致.我的意思是,在某些情况下,我有这个.
private static int StringCompare(string x, string y)
{
int result;
if (x == null)
{
}
}
Run Code Online (Sandbox Code Playgroud)
当我期待这个
private static int StringCompare(string x, string y)
{
int result;
if (x == null)
{
}
}
Run Code Online (Sandbox Code Playgroud)
与此同时,我总是有2个代码缩进,但我希望它是4.
我的问题是
我在Mac OS X/mono上使用emacs C#模式. …
我使用python生成一个冗长而丑陋的XML字符串,我需要通过漂亮的打印机对其进行过滤以使其看起来更好.
我发现这篇文章适用于python漂亮的打印机,但是我必须将XML字符串写入要回读的文件以使用这些工具,如果可能的话我想避免使用这些工具.
什么python漂亮的工具可以在字符串上工作?
在Windows内部本书第5版有360页以下评论.
The stack size for the initial thread is taken from the image—there’s no way to specify another size.
据我所知,对于Windows操作系统,每个线程都有4K或16K(取决于系统)堆栈,并且大小是固定的.
那么.NET中的堆栈怎么样?
我碰巧遇到了以下函数指针.
char (*(*x())[])();
Run Code Online (Sandbox Code Playgroud)
它看起来像以下格式的函数指针数组,但我看不出f - >(*x())的含义.如何解释这个凌乱的函数指针?
char (*f[])();
Run Code Online (Sandbox Code Playgroud)
在John Bode的帮助下,我举了一个例子如下.
#include <stdio.h>
char foo() { return 'a'; }
char bar() { return 'b'; }
char blurga() { return 'c'; }
char bletch() { return 'd'; }
char (*gfunclist[])() = {foo, bar, blurga, bletch};
char (*(*x())[])()
{
static char (*funclist[4])() = {foo, bar, blurga, bletch};
return &funclist;
}
int main()
{
printf("%c\n",gfunclist[0]());
char (*(*fs)[4])();
fs = x();
printf("%c\n",(*fs)[1]());
}
Run Code Online (Sandbox Code Playgroud)
我可以得到预期的结果.
smcho@prosseek temp2> ./a.out a b
而且,您可以在此处找到更好的实施方案.
使用C#,我可以使用string.Join("", lines)将字符串数组转换为字符串.用F#做同样的事情我能做些什么?
我需要从文件中读取行,执行一些操作,然后将所有行连接成一行.
当我运行此代码时
open System.IO
open String
let lines =
let re = System.Text.RegularExpressions.Regex(@"#(\d+)")
[|for line in File.ReadAllLines("tclscript.do") ->
re.Replace(line.Replace("{", "{{").Replace("}", "}}").Trim(), "$1", 1)|]
let concatenatedLine = String.Join("", lines)
File.WriteAllLines("tclscript.txt", concatenatedLine)
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误
error FS0039: The value or constructor 'Join' is not defined
Run Code Online (Sandbox Code Playgroud)
我尝试使用此代码let concatenatedLine = lines |> String.concat ""来获取此错误
error FS0001: This expression was expected to have type
string []
but here has type
string
Run Code Online (Sandbox Code Playgroud)
open System.IO
open System
let lines =
let …Run Code Online (Sandbox Code Playgroud) 在stringC#中的类型是引用类型,并通过值拷贝传递引用类型参数的参考,这样我就不需要使用ref修改器.但是,我需要使用ref修饰符来修改输入string.为什么是这样?
using System;
class TestIt
{
static void Function(ref string input)
{
input = "modified";
}
static void Function2(int[] val) // Don't need ref for reference type
{
val[0] = 100;
}
static void Main()
{
string input = "original";
Console.WriteLine(input);
Function(ref input); // Need ref to modify the input
Console.WriteLine(input);
int[] val = new int[10];
val[0] = 1;
Function2(val);
Console.WriteLine(val[0]);
}
}
Run Code Online (Sandbox Code Playgroud)
- 委托可以具有比其方法目标更具体的参数类型.这称为逆变
- 委托的返回类型可以比其目标方法的返回类型更不具体.这称为协方差
而且,这是一个例子.
using System;
delegate void StringAction(string s);
delegate object ObjectRetriever();
class Test
{
static void Main()
{
StringAction sa = new StringAction(ActionObject);
sa("hello");
ObjectRetriever o = new ObjectRetriever(RetrieveString);
object result = o();
Console.WriteLine(result);
}
static string RetrieveString() {return "hello";}
static void ActionObject(object o)
{
Console.WriteLine(o);
}
}
Run Code Online (Sandbox Code Playgroud)
我认为为了使用协方差/逆变,需要使用new如示例中所示,但我似乎得到了相同的结果sa = ActionObject和 o = RetrieveString.(我用Mono测试过).
new用来解释协方差/逆变?object x = Everything inherit from object?这个奇怪的名字来自哪里?它的用途是什么?