没有F#异步包装(在PowerPack中)为既不
TcpListener.BeginAcceptTcpClient()也没有EndAcceptTcpClient().
我如何编写自己的包装器,以便我可以使用let!和async关键字并行运行它?
我如何以编程方式复制一个word文档的内容并使用C#将其粘贴到另一个word文档?
我基本上想要复制个人资料(这是一个单词doc的内容),然后将其插入报告中.
任何帮助将不胜感激
谢谢
假设我在一个名为的命名空间内工作,Org.Company并且该命名空间包含MyClass.我还导入了一个带有命名空间的nuget,该命名空间Company使用一个名为的类调用OtherClass.
所以,当我在我的Org.Company命名空间内工作时,我不能执行以下操作:
Company.OtherClass obj;
因为编译器假定我的意思是:
Org.Company.Otherclass obj
哪个不存在.
所以,据我所知,我实际上必须导入其他名称空间,而不是使用完全限定名称 using Company;
但问题是,我需要OtherClass 从XML文件(Castle Windsor配置文件)中引用它,并且完全限定名称Company.OtherClass不起作用.有没有解决的办法?更改命名空间名称不是一个可行的选择.
编辑: 这是我在Castle Windsor xml文件中的内容
<using assembly="MyProj, Version=1.0.0.0, Culture=neutral" />
...
<component
service="Company.IOtherClass"
type="Company.OtherClass"
/>
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
{"Could not convert string 'Company.OtherClass' to a type. Make sure assembly containing the type has been loaded into the process, or consider specifying assembly qualified name of the type."}
可能是因为它在内部Org.Company而不是在MyProj组件中定义.
我假设如果有一种方法可以添加另一个 …
我有一个方法需要根据搜索返回不同的数据类型.我正在考虑两种方法,因为我是C#的新手,我不知道哪种方法最好,所以请帮我弄清楚.
第一种方法是重载这样的方法:
public int Get(string name){
//...
return intValue;
}
public double Get(string name){
//...
return doubleValue;
}
public string Get(string name){
//...
return stringValue;
}
Run Code Online (Sandbox Code Playgroud)
第二种方法是为每种数据类型设置不同的方法,如下所示:
public int GetInt(string name){
//...
return intValue;
}
public double GetDouble(string name){
//...
return doubleValue;
}
public string GetString(string name){
//...
return stringValue;
}
Run Code Online (Sandbox Code Playgroud)
哪一个是C#最安全的,考虑到这个代码将从DLL发布?
我很想知道,因为我有一个多个默认参数的方法
private string reqLabel(string label, byte fontSize = 10, string fontColour = "#000000", string fontFamily = "Verdana" )
{
return "<br /><strong><span style=\"font-family: " + fontFamily + ",sans-serif; font-size:" +fontSize.ToString() + "px; color:"+ fontColour + "; \">" + label +" : </span></strong>";
}
Run Code Online (Sandbox Code Playgroud)
当我调用方法时,我必须按顺序执行
reqLabel("prerequitie(s)")
reqLabel("prerequitie(s)", 12)
reqLabel("prerequitie(s)", 12 , "blue")
reqLabel("prerequitie(s)", 12 , "blue", "Tahoma")
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,有没有办法跳过前几个默认参数?
假设我想只输入颜色,字体系列如下:
reqLabel("Prerequisite(s)" , "blue" , "Tahoma")
/* or the same with 2 comma's where the size param is supposed to be. */
reqLabel("Prerequisite(s)" …Run Code Online (Sandbox Code Playgroud) 循环提升易失性读数
我已经阅读过很多地方,一个volatile变量不能从循环中提升或者如果,但我找不到这提到C#规范中的任何地方.这是隐藏的功能吗?
所有写入在C#中都是易失的
这是否意味着所有写入都没有相同的属性,就像使用volatile关键字一样?例如,C#中的普通写入具有发布语义?并且所有写入都会刷新处理器的存储缓冲区?
释放语义
这是一种正式的方式,说明当完成易失性写入时处理器的存储缓冲区被清空了吗?
获取语义
这是一种正式的说法是不应该将变量加载到寄存器中,而是每次从内存中获取它吗?
在本文中,Igoro谈到"线程缓存".我完全明白这是想象的,但他实际上指的是:
或者这只是我的想象力?
延迟写作
我读过许多写作可以延迟的地方.这是因为重新排序和存储缓冲区吗?
Memory.Barrier
我知道副作用是在JIT将IL转换为asm时调用"lock or",这就是为什么Memory.Barrier可以解决fx这个例子中对主内存(在while循环中)的延迟写入的原因:
static void Main()
{
bool complete = false;
var t = new Thread (() =>
{
bool toggle = false;
while (!complete) toggle = !toggle;
});
t.Start();
Thread.Sleep (1000);
complete = true;
t.Join(); // Blocks indefinitely
}
Run Code Online (Sandbox Code Playgroud)
但情况总是这样吗?对Memory.Barrier的调用是否总是刷新存储缓冲区,将更新的值提取到处理器缓存中?我知道完整的变量不会被提升到寄存器中,而是每次都从处理器缓存中提取,但由于对Memory.Barrier的调用,处理器缓存会更新.
我在这里的冰上,还是我对volatile和Memory.Barrier的某种理解?
我有一个Visual Studio 2013 Windows Forms C#项目,我之前添加了一个使用Wingdings 3字体的按钮 - 它工作正常.我已经创建了一个新的解决方案并尝试了同样的事情,但每当我选择Wingdings作为任何类型的Windows窗体控件的字体名称时,它总是默认为窗体设计器中的Microsoft Sans Serif字体.对于其他字体,Designer会选择更改.我也注意到同样的问题在我的Visual Studio 2008环境中也很突出.
我是否可能无意中更改了禁用某种类型字体的环境设置?
将值类型的实例分配给另一个实例时,会将该对象逐位复制到目标位置:
private struct Word
{
public Word(char c) { ... }
}
public void Method(Word a)
{
Word b = a; //a is copied and stored in b
}
Run Code Online (Sandbox Code Playgroud)
但是给出以下代码:
private Word _word;
public void Method() {
_word = new Word('x');
}
Run Code Online (Sandbox Code Playgroud)
我怀疑首先评估右侧(RHS)表达式 - 它实例化堆栈上的值类型 - 然后将值复制并存储在_word堆上的字段的位置.
另一种方法是考虑左侧,并直接实例化值类型_word,避免复制对象.
我的怀疑是否正确?如果是,我想可以安全地假设第一个代码块比第二个代码块表现更好.
//1 instantiation + 10k copies
Word[] words = new Word[10000];
Word word = new Word('x');
for (int i = 0; i < 10000; i++)
words[i] = …Run Code Online (Sandbox Code Playgroud) 我面临的问题是我的客户已经在运行应用程序 appA。然后他们转到桌面(而不是杀死 appA),并通过使用 PowerShell 运行 appA.ps1 来升级应用程序的版本。之后,安装后点击 appA -> get an exception。我想根本原因是有另一个实例正在运行。
我的问题是如何检查我的应用程序是否已经在运行?我可以杀死它吗?
另外,我的应用程序是 windows 8 商店,c#。
我对cq的linq查询很新.我有一个字符串列表,我想获得一个新列表或删除所有双字符串.
List<string> zipcodes = new List<string>();
zipcodes.Add("1234");
zipcodes.Add("1234");
zipcodes.Add("1234");
zipcodes.Add("4321");
zipcodes.Add("4321");
List<string> groupbyzipcodes =
(from zip in zipcodes
group zip by zip into newgroup
select newgroup.ToList());
Run Code Online (Sandbox Code Playgroud)
无法隐式转换
'System.collection.Generic.IEnumarable<System.Collections.Generic.List<string>'为'System.collections.Generic.List<string>.存在显式转换(您是否错过了演员?)
c# ×9
.net ×2
asynchronous ×1
casting ×1
clr ×1
copy ×1
f# ×1
generics ×1
kill-process ×1
linq ×1
memory-model ×1
methods ×1
ms-word ×1
namespaces ×1
paste ×1
types ×1
value-type ×1
volatile ×1
winforms ×1