我创建了一个streamReader,但第一个'ReadLine()'读取文件中的第14行,而不是第一行,我不知道为什么会这样.
我的代码是:
StreamReader reader = new StreamReader("argus-BIG.txt");
//create array to hold data values
string[] branchData = new string[11];
//get 11 lines of branch data file and store in an array
for (int i = 0; i < 11; i++)
{
branchData[i] = reader.ReadLine();
}
//new instance of Branch Class
Branch tempBranch = new Branch();
//set branch values from branchData array
tempBranch.setBranchID(branchData[0]);
tempBranch.setBranchNickname(branchData[1]);
tempBranch.setBranchAddressNo(branchData[2]);
tempBranch.setBranchAddressStreet(branchData[3]);
tempBranch.setBranchAddressCity(branchData[4]);
tempBranch.setBranchAddressCountry(branchData[5]);
tempBranch.setBranchAddressPostCode(branchData[6]);
tempBranch.setNearestBranch1(branchData[7]);
tempBranch.setNearestBranch2(branchData[8]);
tempBranch.setNearestBranch3(branchData[9]);
tempBranch.setNoCategories(Convert.ToInt32(branchData[10]));
Run Code Online (Sandbox Code Playgroud)
我写了一个测试应用程序,它工作,然后复制并粘贴代码(看起来与我相同)回到我的主程序,它工作.谢谢你的帮助
我想将两位数的int分成2位数的整数!例如:
20 = 2 and 0
15 = 1 and 5
8 = 0 and 8
Run Code Online (Sandbox Code Playgroud) 我有以下数据库表,其中主题和评论之间的关系是 1:N
Category
id
name
Topic
id
title
category_id
Comment
id
details
topic_id
deleted (boolean)
Run Code Online (Sandbox Code Playgroud)
我想要一个查询来计算每个类别中的评论总数。我有以下 LINQ 查询,但它不起作用:
@foreach (var cat in Model.AllPermissionSets.Keys)
{
var commentCount = cat.Topics.Where(c => c.Comments.deleted != 0).SelectMany(x => x.Comments).Count();
@* some other stuff *@
}
Run Code Online (Sandbox Code Playgroud)
在 Visual Studio 中我收到错误IList<Comment> doesn not contain a definition for deleted...
执行上述操作的正确语法是什么?
在更新项目中,我必须执行以下操作:
将3个数据库从SQL2000移动到SQL2005并同时合并它们.SP和视图中已经有很多交叉数据库查询.当前计划是将每个旧数据库移动到1个数据库中的单独模式中.
这意味着我们还必须更改当前的SP和视图,我们现在拥有:
SELECT OrderId, OrderDate FROM Sales.dbo.Orders
Run Code Online (Sandbox Code Playgroud)
并期望我们必须改变它
SELECT OrderId, OrderDate FROM Sales.Orders
Run Code Online (Sandbox Code Playgroud)
问题是:我们如何尽可能自动化?
我知道SED和类似的更改脚本.我会欢迎有关如何"聪明"的提示,例如分区脚本的策略,性能(大量INSERT INTO行)等.
注意:我确实查看了导入/导出向导,但显然我必须在每个输出表上手动设置Schema,并通过ALTER脚本修复SP.
如果我有这三个类:
public class PropertyDouble
{
private double _value;
public double Value
{ get; set;}
}
public class PropertyInt
{
private int _value;
public int Value
{ get; set;}
}
public class PropertyFloat
{
private float _value;
public float Value
{ get; set;}
}
Run Code Online (Sandbox Code Playgroud)
是否有可能以及如何创建一个我可以构造它的通用类:Double,Int或Float?
在Directory.EnumerateFiles或Directory.GetFiles中允许使用.take()?
我有这个并且有效
Parallel.ForEach(Directory.EnumerateFiles(sourceFolder, "*",
SearchOption.AllDirectories), file =>
{
//DO SOMETHING
});
Run Code Online (Sandbox Code Playgroud)
我只想在例如100个文件中进行循环.所以:
Parallel.ForEach(Directory.EnumerateFiles(sourceFolder, "*",
SearchOption.AllDirectories).Take(100), file =>
{
//DO SOMETHING
});
Run Code Online (Sandbox Code Playgroud)
但是这个周期并没有像我预期的那样被记录100次.
为什么?
我有这样一个列表:C++中的列表
list<int> p[15];
list<int> copy_of_p[15];
Run Code Online (Sandbox Code Playgroud)
C#中的列表
list<int>[15] p;
list<int>[15] copy_of_p;
Run Code Online (Sandbox Code Playgroud)
我尝试使用此代码在C#中制作10000份副本
for (int counter = 0; counter < 15; counter++)
{
copy_of_p[counter] = p[counter].toList();
}
Run Code Online (Sandbox Code Playgroud)
花了大约10 MiliSecs
然后我用这段代码在c ++中做了同样的事情
for (int counter = 0; counter < 15; counter++)
{
copy_of_p[counter] = p[counter];
}
Run Code Online (Sandbox Code Playgroud)
它花了大约1200 MiliSecs
这意味着在c ++中应该有一种方法来复制列表至少与C#一样快.你能指导我扔这个吗?
PS:我试过了
copy(p.begin(), p.end(), copy_of_p[counter]);
Run Code Online (Sandbox Code Playgroud)
但它造成了构建错误
如何将以下代码转换为使用?:运算符..是否可能?
tbtotalamount.Text = string.Format("{0:n2}", dtl.Compute("sum(NetPay)", ""));
if (tbtotalamount.Text.Length == 0)
{
tbtotalamount.Text = "0";
}
Run Code Online (Sandbox Code Playgroud) 在此查询中:
var test = db.table.Where(x=>x.id == x).Where(x=>x.name == name).ToList();
Run Code Online (Sandbox Code Playgroud)
在SQL语言中使用AND或OR是一样的吗?
c# ×7
linq ×2
.net ×1
c++ ×1
copy ×1
foreach ×1
int ×1
lambda ×1
linq-to-sql ×1
list ×1
math ×1
sql-server ×1
streamreader ×1
string ×1