有谁知道检测哪个版本的Office的最佳方法是什么?另外,如果安装了多个版本的Office,我想知道它们是什么版本.如果我能够检测到(/)安装的Excel的特定版本,则会获得奖励.
我有一个低脑波日...有没有人知道一种快速而优雅的方式来转换一个字典,以便键成为价值,反之亦然?
例:
var originalDictionary = new Dictionary<int, string>() {
{1, "One"}, {2, "Two"}, {3, "Three"}
};
Run Code Online (Sandbox Code Playgroud)
变
var newDictionary = new Dictionary<string, int>();
// contents:
// {
// {"One", 1}, {"Two", 2}, {"Three", 3}
// };
Run Code Online (Sandbox Code Playgroud) 将对象转换为double的最快方法是什么?我现在正处于一段代码中,其中包括:
var d = double.TryParse(o.ToString(), out d); // o is the Object...
Run Code Online (Sandbox Code Playgroud)
首先想到的是将其重写为
var d = Convert.ToDouble(o);
Run Code Online (Sandbox Code Playgroud)
但实际上会更快吗?
编辑: 除了运行配置文件(顺便说一下,我强烈建议任何开发人员使用JetBrains dotTrace),我运行了Reflector,这帮助我提出了以下内容(或多或少相关的代码部分):
if (o is IConvertible)
{
d = ((IConvertible)o).ToDouble(null);
}
else
{
d = 0d;
}
Run Code Online (Sandbox Code Playgroud)
原始代码double.TryParse()
在140ms内执行.新代码在34ms内执行.我几乎可以肯定这是我应该采取的优化路径,但在我这样做之前,有没有人看到我的"优化"代码出现问题?在此先感谢您的反馈!
我想一般扁平一些json所以我可以转换为数据表并使用c#绑定到数据网格
什么是最好的办法,记住我不知道我要下多少级别?
例如
{ "appointmentid": 4, "policyid": 1, "guid": "00000000-0000-0000-0000-000000000000", "number": "1234567890", "ampm": "false", "date": "2015-09-08T00:00:00", "vehicle": { "id": 1, "guid": "00000000-0000-0000-0000-000000000000", "make": null, "model": null }, "installer": { "installerid": "1", "name": "Installer 1", "contact": "qwerty", "qascore": "0", "address1": "qwerty", "address2": "qwerty", "address3": null, "address4": null, "city": "qwertyu", "county": "qwertyu", "postcode": "asdfghj", "country": "GB", "email": "asdfghj", "web": "asdfghjk", "archived": false }, "installations": [ { "installationid": 6, "installationstatus": { "installationstatusid": 4, "installationstatus": "FAIL" }, "isactive": true }, { "installationid": 7, "installationstatus": …
我有一个用户控件,它有一个ComboBox和一个SelectedIndexChanged事件处理程序.在事件处理程序中,我需要能够分辨出之前选择的索引是什么...有人能指出我正确的方向吗?
private void cboTargetMode_SelectedIndexChanged(object sender, EventArgs e)
{
// need to get the previously selected index and do some handling here...
// ... some handler code here ...
switch (cboTargetMode.SelectedIndex)
{
case 1: // ..... some code here...
break;
case 2: // ..... some code here...
break;
case 3: // ..... some code here...
break;
default: // ..... some code here...
break;
}
}
Run Code Online (Sandbox Code Playgroud) 例如,如何GroupId
使用LINQ 对以下记录进行分组,并将每个组中的所有其他列相加?(从而将每个组中的所有行合并为一个)
var list = new List<Foo>()
{
new Foo() { GroupId = 0, ValueA = 10, ValueB = 100 },
new Foo() { GroupId = 1, ValueA = 30, ValueB = 700 },
new Foo() { GroupId = 1, ValueA = 40, ValueB = 500 },
new Foo() { GroupId = 2, ValueA = 80, ValueB = 300 },
new Foo() { GroupId = 2, ValueA = 20, ValueB = 200 },
new Foo() { GroupId = …
Run Code Online (Sandbox Code Playgroud) 我是C#的新手,我正在尝试创建一个简单的客户端服务器聊天应用程序.
我在我的客户端窗体上有RichTextBox,我试图从另一个类的服务器更新该控件.当我尝试这样做时,我得到错误:"跨线程操作无效:控制textBox1从其创建的线程以外的线程访问".
这里是我的Windows窗体的代码:
private Topic topic;
public RichTextBox textbox1;
bool check = topic.addUser(textBoxNickname.Text, ref textbox1, ref listitems);
Run Code Online (Sandbox Code Playgroud)
主题类:
public class Topic : MarshalByRefObject
{
//Some code
public bool addUser(string user, ref RichTextBox textBox1, ref List<string> listBox1)
{
//here i am trying to update that control and where i get that exception
textBox1.Text += "Connected to server... \n";
}
Run Code Online (Sandbox Code Playgroud)
那怎么办呢?如何从另一个线程更新文本框控件?
我正在尝试使用.net远程处理来创建一些基本的聊天客户端/服务器应用程序.我想将Windows窗体客户端应用程序和控制台服务器应用程序作为单独的.exe文件.这里我试图从客户端调用服务器函数AddUser,我想要AddUser函数更新我的GUI.我已经修改了代码,因为你建议使用Jon,但是现在代替了跨线程异常,我得到了这个异常... "SerializationException:Assembly中的类型主题没有被标记为可序列化".
生病了我的整个代码,尽量保持简单.
任何建议都是受欢迎的.非常感谢.
服务器:
namespace Test
{
[Serializable]
public class Topic : MarshalByRefObject
{
public bool AddUser(string user, …
Run Code Online (Sandbox Code Playgroud) 我是德国的计算机科学专业的学生.我的教授用了以下问题来思考:
'给定对单个链表中的节点的引用(不是最后一个节点).给出一个算法,从列表中删除该元素,该元素具有O(1)复杂度,同时保持完整性.
我想到了这一点,但我很确定,没有这样的算法.因为它是单个链表,所以必须遍历列表中的每个节点,直到到达应该删除的节点,因为您必须在删除之前修改节点中的下一个指针.这将导致O(n)复杂性.
我错过了什么吗?
我一直被告知对接口的编程更好,所以我的方法的参数我会设置IList<T>
而不是List<T>
..
但这意味着我必须施展才能List<T>
使用某些方法,Find
例如,我想到了一个方法.
为什么是这样?我应该继续针对接口进行编程,还是继续进行转换或还原?
我有点困惑为什么Find
(例如)没有继承自IList<T>
哪些List<T>
.