我正在对各种类型的集合操作进行比较.
所以我有一个泛型类
public class Comparer<T, Tid>
...
public bool Equals(T x, T y)
{
var xid = m_idfunc(x);
var yid = m_idfunc(y);
return (Tid)xid == (Tid)yid;
}
Run Code Online (Sandbox Code Playgroud)
其中m_idfunc是传递给Comparer构造函数的lambda,它是
Func<T,Tid>
Run Code Online (Sandbox Code Playgroud)
我用Tid = string创建了一个比较器.我进入等于函数xid = string1,yid = string2
如果string1和string 2相同("foo"和"foo"说)
xid == yid
Run Code Online (Sandbox Code Playgroud)
产生错误
(Tid)xid == (Tid)yid
Run Code Online (Sandbox Code Playgroud)
也产生错误(它不应该是必要的 - 我只是变得绝望)
继承我的直接窗口 - 暂停返回xid == yid行
yid.GetType() == typeof(string)
true
xid.GetType() == typeof(string)
true
xid==yid
false
(string)xid==(string)yid
true
xid.Equals(yid)
true
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?
我正在使用EWS托管API来进行推送订阅.工作良好
现在我想取消订阅
托管API文档http://msdn.microsoft.com/en-us/library/office/dn458791(v=exchg.150).aspx说使用service.EndSubscribeToPushNotifications.这显然是错误的 - 这个函数是一对BeginSubscribeTo...异步操作(反射器证实了这一点)
我没有看到明显的方法ExchangeService.
一般的EWS文档http://msdn.microsoft.com/en-us/library/office/aa564263(v=exchg.150).aspx说发送这个XML,但它只用于拉动操作
那我该怎么办?
这让我感到惊讶
>set foo("bar") 12
12
>parray foo
foo("bar") = 12
>set foo(bar) 12
12
>parray foo
foo("bar") = 12
foo(bar) = 12
Run Code Online (Sandbox Code Playgroud)
字面上的foo似乎和"foo"不一样.但是
>string length foo
3
>string length "foo"
3
Run Code Online (Sandbox Code Playgroud)
我不明白的是什么
[DBG]: PS C:\Windows\system32>>> echo [uint32]::maxvalue
[uint32]::maxvalue
Run Code Online (Sandbox Code Playgroud)
和
[DBG]: PS C:\Windows\system32>>> $mv = [uint32]::maxvalue
[DBG]: PS C:\Windows\system32>>> echo $mv
4294967295
Run Code Online (Sandbox Code Playgroud)
我确信powershell有一个很好的理由这样做:-).有道路我可以告诉它不要这样做.我实际上是传递和int到一个函数,有时我想传递maxvalue
我知道我能做到
$mv = [uint32]::maxvalue
MyFunc $mv
Run Code Online (Sandbox Code Playgroud)
我想知道是否有类似的东西
MyFunc ([uint32]::maxvalue)
MyFunc `[uint32::maxvalue`
Run Code Online (Sandbox Code Playgroud)
等等
本以为C不会再给我带来惊喜了,但这却让我大吃一惊。
const int NUM_FOO = 5;
....
int foo[NUM_FOO];
==>error C2057: expected constant expression
Run Code Online (Sandbox Code Playgroud)
我的 C++ 经验让我在内部#define尽可能地反对。所以这真是一个惊喜。VS2019,使用/TC编译。我认为 C99 无论如何都允许可变大小的数组。
任何人都可以解释为什么会发生拒绝,因为编译器在编译时肯定知道数组的大小?
C99不是允许可变大小数组吗?
我有一个工会,定义如下:
union CellType {
std::string str;
int i;
double d;
Money<2> m; // Custom class for fixed-decimal math.
};
Run Code Online (Sandbox Code Playgroud)
然后,我就有了这样的联合的向量。
std::vector<CellType> csvLine;
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何将值附加到向量的末尾?我通常使用字符串、整数等的push_backfor vector,但是当向量元素是并集时无法完全弄清楚语法。任何帮助,将不胜感激。
(是的,这个类一次读取一行 CSV 文件,如果这有什么区别的话。)
这是失败的 MRE
#include <vector>
#include <iostream>
union CellType {
std::string str;
int i;
double d;
// Money<2> m; // Custom class for fixed-decimal math.
};
int main() {
std::vector<CellType> csvLine;
CellType c;
c.str = "foo";
csvLine.push_back(c);
}
Run Code Online (Sandbox Code Playgroud)
Money 被注释掉是因为与 MRE 无关
错误
严重性代码说明项目文件行抑制状态错误 C2280 'CellType::CellType(void)':尝试引用已删除的函数 ConsoleApplication1 C:\work\ConsoleApplication1\ConsoleApplication1.cpp 22
我有
public static void SecureTcpRpc<InterfaceType>(string uri,
Action<InterfaceType> action)
where InterfaceType : class;
Run Code Online (Sandbox Code Playgroud)
然后我在这里使用它
private static AuthorizedActionResult
RunChannelAction<T>(IEnumerable<string> uris,
Func<T, AuthorizedActionResult> actionFunc)
where T : IPingable
{
WcfClient.SecureTcpRpc<T>....
Run Code Online (Sandbox Code Playgroud)
编译器不喜欢我将T限制为IPingable.我不明白为什么它反对.IPingable是一种引用类型,因此它匹配SecureTpcRpc方法的约束.但是编译器说"T必须是引用类型"
我知道如何在c#中制作可插拔的东西.定义一个接口,Activator.CreateInstance(<class>)等等.或者我可以有一个显式创建插件类实例的代码路径.很多种方法.
但是,如果我想要插件的服务是静态的(我知道我可以重构,所以它不是,但这不是问题的重点)
具体例子.我有一个提供磁盘I/O抽象的类(读取文件,列表目录,....).现在我想要这种抽象的不同实现,它可以提供来自真实FS,数据库的文件.
根据Olivier Jacot-Descombes的回复,我会有一个FileSystem类(这是真的)这样的
public static class FileSystem
{
static IFSImplemenation s_imple;
static FileSystem()
{
if(<some system setting>)
// converted to singleton instead of static
s_imple = new OldFileSystem()
else
s_imple = new DbFileSystem();
}
public static byte[] ReadFile(string path)
{
return s_imple.ReadFile(path);
}
...
}
Run Code Online (Sandbox Code Playgroud)
重申 - 我有一大堆代码,我不想改变,所以保持调用签名相同很重要 - 这个解决方案实现了
如果我做
s, err := os.Stat(path)
Run Code Online (Sandbox Code Playgroud)
而err != nil我需要知道,如果该文件不存在VS我没有权限来访问它,等我如何获得潜在的错误代码?阅读os包文档似乎建议我阅读错误字符串的文本 - 当然不是吗?
我通常用java编程,最近看一些c代码.我遇到了这个程序,我不知道这个指针是如何工作的.我知道指针存储了地址,所有但都无法通过程序.请告诉我输出如何变为8?
#include <stdio.h>
int fun(int n, int * f_p) {
int t, f;
if (n <= 1) {
*f_p = 1;
return 1;
}
t = fun(n - 1, f_p);
f = t + *f_p;
*f_p = t;
return f;
}
int main() {
int x = 15;
printf("%d\n", fun(5, &x));
return 0;
}
Run Code Online (Sandbox Code Playgroud)