我想检索上次更新表(插入,删除,更新).
我试过这个查询.
SELECT last_user_update
FROM sys.dm_db_index_usage_stats
WHERE object_id=object_id('T')
Run Code Online (Sandbox Code Playgroud)
但是服务重启后数据不会持续存在.
即使服务重新启动,我也想保留统计信息.我怎样才能实现它?
我有一个包含一些值的List.
例:
List<object> testData = new List <object>();
testData.Add(new List<object> { "aaa", "bbb", "ccc" });
testData.Add(new List<object> { "ddd", "eee", "fff" });
testData.Add(new List<object> { "ggg", "hhh", "iii" });
Run Code Online (Sandbox Code Playgroud)
我有一个类似的课程
class TestClass
{
public string AAA {get;set;}
public string BBB {get;set;}
public string CCC {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
如何转换testData
为类型List<TestClass>
?
除此之外有没有办法转换?
testData.Select(x => new TestClass()
{
AAA = (string)x[0],
BBB = (string)x[1],
CCC = (string)x[2]
}).ToList();
Run Code Online (Sandbox Code Playgroud)
我不想提及列名,因此无论类更改如何,我都可以使用此代码.
我也有一个IEnumerable<Dictionary<string, object>>
有数据.
如何动态创建对象?
string[] columnNames = { "EmpName", "EmpID", "PhoneNo" };
List<string[]> columnValues = new List<string[]>();
for (int i = 0; i < 10; i++)
{
columnValues.Add(new[] { "Ramesh", "12345", "12345" });
}
List<Dictionary<string, object>> testData = new List<Dictionary<string, object>>();
foreach (string[] columnValue in columnValues)
{
Dictionary<string, object> data = new Dictionary<string, object>();
for (int j = 0; j < columnNames.Count(); j++)
{
data.Add(columnNames[j], columnValues[j]);
}
testData.Add(data);
}
Run Code Online (Sandbox Code Playgroud)
虚构类(代码中没有类):
class Employee
{
string EmpName { get;set; }
string EmpID { get;set; } …
Run Code Online (Sandbox Code Playgroud) 我们正在为我们的应用程序实现即插即用模块,用户可以在运行时加载和卸载所需的类库.所以我决定使用MEF和类库的影子复制.
这里的事情是每个类库可能具有需要由用户设置的不同配置属性.我的主应用程序不了解类库中的配置.
现在问题是当我尝试将加载了类库的应用程序配置文件从一个应用程序域传输到另一个应用程序域时.
没有MEF,我刚从Settings.Default
类库中返回,我在主应用程序中使用它来编辑设置.使用MEF和阴影复制,它似乎不起作用,因为
MarshalByRefObject
在设置文件上实现,因为设置文件已经扩展ApplicationSettingsBase
,这是一个抽象类,而c#不支持多重继承.目前我正在创建一个类,它将所有属性保存为字符串,并根据此类内容在主应用程序中创建GUI.
public class ExtensionModuleConfiguration : MarshalByRefObject
{
public string Name { get; set; }
public string Value { get; set; }
public List<string> Options { get; set; }
public UIElements ToolUIElement { get; set; }
}
public enum UIElements
{
ComboBox,
TextBox
}
Run Code Online (Sandbox Code Playgroud)
我必须说这不是最好的解决方案.有人可以建议一种更好的方法来设置MEF中类库的配置吗?
我有一个List< Dictionary < string, object >>
变量如下。
private static List<Dictionary<string, object>> testData = new List<Dictionary<string, object>>(100);
// Just Sample data for understanding.
for (int i = 0; i < 100; i++)
{
var test = new Dictionary<string, object>
{
{ "aaa", "aaa" + i % 4 },
{ "bbb", "bbb" + i % 4 },
{ "ccc", "ccc" + i % 4 },
{ "ddd", "ddd" + i % 4 },
{ "eee", "eee" + i % 4 }, …
Run Code Online (Sandbox Code Playgroud) 我有一个 IEnumerable < Dictionary < string, object > >
对象.
我想在数组中得到"aaavalue""bbbvalue""cccvalue""dddvalue".
样本数据:
IEnumerable<Dictionary<string, object>> testData = new IEnumerable<Dictionary<string, object>>();
/* Values in testData will be like
[0] -
aaa - aaaValue (Key, Value)
bbb - bbbValue
ccc - cccValue
ddd - dddValue
[1] -
aaa - aaaValue (Key, Value)
bbb - bbbValue
ccc - cccValue
ddd - dddValue
and so on */
Run Code Online (Sandbox Code Playgroud)
我知道可以使用Reflection或LINQ.但我无法弥补.
请帮忙..
回答:
IEnumerable<Dictionary<string, object>> enumerable = testData as List<Dictionary<string, object>> ?? testData .ToList();
foreach (Dictionary<string, object> objects in enumerable) …
Run Code Online (Sandbox Code Playgroud) 我有List<Dictionary<string, string>>
一些数据对象.
/* Values in the list will be like
[0] -
aaa - aaaValue1 (Key, Value)
bbb - bbbValue1
ccc - cccValue1
ddd - dddValue1
[1] -
aaa - aaaValue2 (Key, Value)
bbb - bbbValue2
ccc - cccValue2
ddd - dddValue2
and so on */
Run Code Online (Sandbox Code Playgroud)
我想List<string>
在字典中获得不同的值(),其中键等于"ccc",键"bbb"的值等于"bbbValue1".
预期结果:
返回一个字符串列表,其中包含字符值,其中键等于"ccc",键"bbb"的值等于"bbbValue1" List<Dictionary<string, string>>
.
从Observable集合中我想过滤名称为aaa,bbb,ccc,ddd,eee的项目.这该怎么做?
public class Item
{
public string ItemName {get; set;}
public int ItemNumber {get; set;}
}
public ObservableCollection<Item> _items;
public List<string> searchItems = new List<string>(5);
searchItems.Add("aaa");
searchItems.Add("bbb");
searchItems.Add("ccc");
searchItems.Add("ddd");
searchItems.Add("eee");
Run Code Online (Sandbox Code Playgroud)
我在linq中尝试了一下..但我不知道怎么做列表..
var filteredItems = from item in _items
where _items.Any(x => x.ItemName == "aaa")
select x;
Run Code Online (Sandbox Code Playgroud) 我有一个静态类中的静态变量列表.
namespace Test
{
public static class Numbers
{
public static readonly int One = 1;
public static readonly int Five = 5;
public static readonly int Ten = 10;
public static readonly int Eleven = 11;
public static readonly int Fifteen= 15;
}
}
Run Code Online (Sandbox Code Playgroud)
我想在课堂上随机选择一个变量.我怎样才能做到这一点?
int randomVariable = SomeFunction(Numbers);
Run Code Online (Sandbox Code Playgroud) 我正在编写一个实时应用程序,它每秒接收大约2000条消息,这些消息被推入队列中.我编写了一个后台线程来处理队列中的消息.
private void ProcessSocketMessage()
{
while (!this.shouldStopProcessing)
{
while (this.messageQueue.Count > 0)
{
string message;
bool result = this.messageQueue.TryDequeue(out message);
if (result)
{
// Process the string and do some other stuff
// Like updating the received message in a datagrid
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
上述代码的问题在于它使用了大约12%CPU(2.40 GHz双核处理器)的疯狂处理能力.
我有4个类似于上面的块,它实际上占用了50%的CPU计算能力.在上面的代码中有什么可以优化的吗?
在第二次循环结束之前添加100 ms的线程休眠似乎会使性能提高50%.但我做错了吗?
c# multithreading winforms task-parallel-library tpl-dataflow