我有一个List<List<string>>
名为_DataCollection,其中每个嵌套列表具有相同数量的值.尽管是所有字符串,但嵌套列表中的值将是由字母数字字符,空字符串或货币值组成的字符串.例如
_DataCollection[0] = {"tom", "abc", "$525.34", "$123"}
_DataCollection[1] = {"dick", "xyz", "$100", "$234"}
_DataCollection[2] = {"harry", "", "$250.01", "$40"}
_DataCollection[2] = {"bob", "", "$250.01", ""}
Run Code Online (Sandbox Code Playgroud)
我需要做的是想出一种方法来对所有嵌套列表中每个索引的所有值求和,并将其添加到列表中:
newSumList[0] = "N/A" since "tom" + "dick" + "harry" + "bob" can't be aggregated.
newSumList[1] = "N/A" since "abc" + "xyz" + "" + "" can't be aggregated.
newSumList[2] = "1125.36"
newSumList[3] = "397" even though the last value of the last nested list is "".
Run Code Online (Sandbox Code Playgroud)
基本上,每个索引的嵌套列表中的所有数值总和.
我能想到的唯一方法是迭代这些并保持运行总计,但我想知道我是否可以使用LINQ或其他东西来做.
我有两台服务器:SQLSERVER01
并且SQLSERVER02
我正在尝试更新来自SERVER01
(SERVER02
是SERVER01
链接服务器)的数据。
我的更新查询当前是动态的,看起来像这样
DECLARE @SQL NVARCHAR(MAX)
DECLARE @ID INT
SET @ID = 1
Set @SQL = 'Update SERVER01.MyDatbase.dbo.MyTable
set ModifiedDate = GetDate(), SomeOtherValue = ''xyz''
Where Id = ' Convert(varchar(10), @ID)
Run Code Online (Sandbox Code Playgroud)
如果我现在打电话
EXEC(@SQL)
Run Code Online (Sandbox Code Playgroud)
它有时会起作用,但有时它会挂在那里很长时间,当我跑步时sp_active
我会看到PREEMPTIVE_OLEDBOPS
。
所以,我然后尝试使用开放查询,如下所示
Select *
From OpenQuery(SERVER01,
'Update SERVER01.MyDatbase.dbo.MyTable
set ModifiedDate = GetDate(), SomeOtherValue = ''xyz''
Where Id = 1')
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
链接服务器“SERVER01”的 OLE DB 提供程序“SQLNCLI11”指示该对象没有列,或者当前用户对该对象没有权限。
当我运行以下选择查询时,我成功返回了我尝试更新的行:
Select *
From OpenQuery(SERVER01,
'Select *
From SERVER01.MyDatbase.dbo.MyTable
Where …
Run Code Online (Sandbox Code Playgroud) I have a jagged array where the series of column names is contained in the first row of the array and the data is contained in subsequent rows. I need to convert this into a Json string containing a series of objects with property names extracted from the first row.
例如,如果我有:
var arr = [["Age", "Class", "Group"], ["24", "C", "Prod"], ["25", "A", "Dev"], ["26", "B", "Test"]];
Run Code Online (Sandbox Code Playgroud)
我需要结束:
[
{
"Age": "24",
"Class": "C",
"Group": "Prod"
},
{
"Age": "25",
"Class": …
Run Code Online (Sandbox Code Playgroud) 我想知道用空值替换数组中空字符串的最有效方法.
我有以下数组:
string[] _array = new string [10];
_array[0] = "A";
_array[1] = "B";
_array[2] = "";
_array[3] = "D";
_array[4] = "E";
_array[5] = "F";
_array[6] = "G";
_array[7] = "";
_array[8] = "";
_array[9] = "J";
Run Code Online (Sandbox Code Playgroud)
我目前正在通过以下方式替换空字符串:
for (int i = 0; i < _array.Length; i++)
{
if (_array[i].Trim() == "")
{
_array[i] = null;
}
}
Run Code Online (Sandbox Code Playgroud)
它在小型数组上工作正常,但我正在追逐一些在执行任务时效率最高的代码,因为我正在使用的数组可能要大得多,我会一遍又一遍地重复这个过程.
是否有linq查询或更高效的东西?
我试图找到一种有效的方法来改变数组的长度和数组中的元素。例如,如果我有
var arr = [["Name", "Age", "Lightsaber Color"], ["Luke Skywalker", "22", "Green"], ["Yoda", "900", "Green"], ["Obi Wan Kenobi", "59", "Blue"]]
Run Code Online (Sandbox Code Playgroud)
我想结束
var arr = [["Name", "Age"], ["Luke Skywalker", "22"], ["Yoda", "900"]]
Run Code Online (Sandbox Code Playgroud)
我已经编写了一些代码来做到这一点,但我想确保我改变嵌套数组长度的方式(因为没有更好的术语)尽可能有效。
我有:
var arr = [["Name", "Age", "Lightsaber Color"], ["Luke Skywalker", "22", "Green"], ["Yoda", "900", "Green"], ["Obi Wan Kenobi", "59", "Blue"]]
arr.length = 3; // Removes the Obi Wan entry
console.log(arr);
for(var i = 0; i < arr.length; i++){
arr[i].length = 2 // Removes lightsaber color
};
console.log(arr)
Run Code Online (Sandbox Code Playgroud)
我希望优化的代码是 …
arrays ×3
c# ×2
javascript ×2
linq ×2
json ×1
list ×1
nested ×1
openquery ×1
sql-server ×1
sql-update ×1