我有一个关于Value类型中的类型构造函数的问题.这个问题的灵感来自Jeffrey Richter在CLR中通过C#3rd ed编写的内容,他说(在第195页 - 第8章)你不应该在值类型中实际定义类型构造函数,因为有时候CLR不会调用它.
所以,例如(好吧......实际上是Jeffrey Richters的例子),即使通过查看IL,我也无法解决为什么在以下代码中没有调用类型构造函数:
internal struct SomeValType
{
static SomeValType()
{
Console.WriteLine("This never gets displayed");
}
public Int32 _x;
}
public sealed class Program
{
static void Main(string[] args)
{
SomeValType[] a = new SomeValType[10];
a[0]._x = 123;
Console.WriteLine(a[0]._x); //Displays 123
}
}
Run Code Online (Sandbox Code Playgroud)
因此,对类型构造函数应用以下规则,我只是看不出为什么根本没有调用上面的值类型构造函数.
所以......我无法理解为什么我看不到这个类型的数组正在被构造.
我最好的猜测是它可能是:
最佳实践等帮助,我只是对它非常感兴趣,因为我希望能够亲眼看到它为什么不被调用.
编辑:我在下面添加了我自己的问题的答案,只是引用杰弗里里希特所说的.
如果有人有任何想法,那将是辉煌的.非常感谢,詹姆斯
我正在寻找有关如何检测运行时平台以揭示Microsoft .Net二进制反序列化失败的源类型的见解.
When using BinaryFormatter.Deserialize(StreamingContextStates.CrossMachine)
and one of the types does not exist in the current binaries; instead of throwing an error, .Net inserts the object [TypeLoadExceptionHolder]
. Particularly for collections, this causes no immediate problem.
Subsequently when the collection is serialized for transmission between application tiers; the platform receives a 'serialization failure' because [TypeLoadExceptionHolder]
cannot be serialized. So the resulting error is useless for actually providing clues as to the source-type that caused the problem. Now the hunt (time …
My friend has a web site on ovh.com.Since a couple of days, the site is flagged as dangerous by google.
I had a look in the files (the site only contains only html, css, pjg) and it appears that a new line of code:
<script>http://...page.php</script></body>
Run Code Online (Sandbox Code Playgroud)
(I do not remember the exact url) has been added in some of the html pages. This is obviously a virus that would be run when the page is displayed.
If I delete this line …
我试图在首次启动时将我的应用程序包中的一些文件复制到文档目录.我有第一次启动的检查,但为了清楚起见,它们未包含在代码段中.问题是我正在复制到文档目录(已经存在),在文档中,它说明:
在操作之前,dstPath不得存在.
对我来说直接复制到文档根目录的最佳方法是什么?我想这样做的原因是允许iTunes文件共享支持.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Populator"];
NSLog(@"\nSource Path: %@\nDocuments Path: %@", sourcePath, documentsDirectory);
NSError *error = nil;
if([[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:documentsDirectory error:&error]){
NSLog(@"Default file successfully copied over.");
} else {
NSLog(@"Error description-%@ \n", [error localizedDescription]);
NSLog(@"Error reason-%@", [error localizedFailureReason]);
}
...
return YES;
}
Run Code Online (Sandbox Code Playgroud)
谢谢
如何在WPF中为按钮指定快捷键?
谷歌搜索给了我答案,在标准的Winforms中追加_而不是'&'.
所以在我做完如下之后:
<Button Name="btnHelp" Content="_Help"></Button>
Run Code Online (Sandbox Code Playgroud)
我没有发现'H'下划线.
这是第一个问题.
第二个问题是,如何在运行时按Alt + H后执行该操作.如果只是为了示例而显示一个消息框就足够了.
我正在使用C#,WPF
谢谢.
刚遇到这个问题:
List<DataNode> a1 = new ArrayList<DataNode>();
List<Tree> b1 = a1; // compile error: incompatible type
Run Code Online (Sandbox Code Playgroud)
DataNode类型是Tree的子类型.
public class DataNode implements Tree
Run Code Online (Sandbox Code Playgroud)
令我惊讶的是,这适用于数组:
DataNode[] a2 = new DataNode[0];
Tree[] b2 = a2; // this is okay
Run Code Online (Sandbox Code Playgroud)
这有点奇怪.谁能对此作出解释?
有人可以帮我开始在Flash Builder 4中使用ant.我之前从未使用过ant,所以我是一个完整的新手.我首先需要知道如何安装它,以及如何完成基础知识.
任何帮助表示赞赏.
我们正试图想出一些接近简单直接模型的东西,用于在WebLogic中定位JMS资源(我知道这很有可能).队列和主题可以轻松而直观地映射到WebLogic服务器上运行的JMS服务器,但外部服务器及其中的资源似乎更棘手.
在WLS 10.0和10.3中,首先,外部服务器不是在JMS服务器旁边定义,而是作为JMS模块的成员定义.其次,默认情况下,它们定位到它们所定义的JMS模块的目标,即WLS集群或WLS服务器,而不是通过子部署针对JMS服务器的"非外部"资源.
但是,通过高级定位,还可以在JMS服务器上定位外部服务器.这导致模型相对于外来/"非外来"JMS资源更加对称.
高级定位http://dexter.xebialabs.com/Media/foreign_server_advanced_targeting.png
所以,问题是:
提前致谢!
安德鲁菲利普斯
我有一个案例课
case class ~[a,b](_1:a, _2:b)
Run Code Online (Sandbox Code Playgroud)
当我想做pattetn匹配
new ~("a", 25) match{
case "a" ~ 25 =>
}
Run Code Online (Sandbox Code Playgroud)
我可以使用这种方式,因为"a" ~ 25
和~("a", 25)
是等价的.但如果我想new ~("a", new ~("b", 25))
通过{case "a" ~ "b" ~ 25 => }
麻烦来匹配开始.我知道这些陈述并不等同.那么,如何 new ~("a", new ~("b", 25))
呈现?按什么规则?
我有一些正在使用boost
库的中型项目,因此在调试应用程序性能方面受到了影响(Visual Studio 2008).
我现在使用的解决方案意味着即使在调试模式下打开函数内联,这也带来了足够的性能,但肯定会有一些缺点.
如果我强制使用函数inlining(/Ob2
)开关,有谁知道在调试功能方面我会失去什么?
也许有人对加速boost /其他模板库的调试性能有任何其他想法?