今天MS发布了Visual Studio Code文件/文件夹编辑器.第一个限制是它似乎是单实例应用程序.有没有办法获得多个实例,或者让它同时打开多个文件夹?
我的根本问题是,当using
调用Dispose
a时StreamWriter
,它也会处理BaseStream
(同样的问题Close
).
我有一个解决方法,但正如你所看到的,它涉及复制流.有没有办法这样做而不复制流?
这样做的目的是将字符串(最初从数据库中读取)的内容获取到流中,因此可以由第三方组件读取该流.
注意:我无法更改第三方组件.
public System.IO.Stream CreateStream(string value)
{
var baseStream = new System.IO.MemoryStream();
var baseCopy = new System.IO.MemoryStream();
using (var writer = new System.IO.StreamWriter(baseStream, System.Text.Encoding.UTF8))
{
writer.Write(value);
writer.Flush();
baseStream.WriteTo(baseCopy);
}
baseCopy.Seek(0, System.IO.SeekOrigin.Begin);
return baseCopy;
}
Run Code Online (Sandbox Code Playgroud)
用作
public void Noddy()
{
System.IO.Stream myStream = CreateStream("The contents of this string are unimportant");
My3rdPartyComponent.ReadFromStream(myStream);
}
Run Code Online (Sandbox Code Playgroud)
理想情况下,我正在寻找一个名为的假想方法BreakAssociationWithBaseStream
,例如
public System.IO.Stream CreateStream_Alternate(string value)
{
var baseStream = new System.IO.MemoryStream();
using (var writer …
Run Code Online (Sandbox Code Playgroud) 如果我有以下情况:
StreamWriter MySW = null;
try
{
Stream MyStream = new FileStream("asdf.txt");
MySW = new StreamWriter(MyStream);
MySW.Write("blah");
}
finally
{
if (MySW != null)
{
MySW.Flush();
MySW.Close();
MySW.Dispose();
}
}
Run Code Online (Sandbox Code Playgroud)
MySW.Dispose()
即使提供了,我可以打电话并跳过关闭吗?是否存在任何不能按预期工作的Stream implament(如CryptoStream)?
如果没有,那么以下只是错误的代码:
using (StreamWriter MySW = new StreamWriter(MyStream))
{
MySW.Write("Blah");
}
Run Code Online (Sandbox Code Playgroud) 如果我想将单个数字转换为char
数字值,例如,如果:
char c = '5';
Run Code Online (Sandbox Code Playgroud)
而我想c
坚持5
而不是'5'
,100%便携式这样做吗?
c = c - '0';
Run Code Online (Sandbox Code Playgroud)
我听说所有字符集都按顺序存储数字,所以我假设是这样,但我想知道是否有一个有组织的库函数来进行这种转换,以及它是如何按常规方式完成的.我是一个真正的初学者:)
我可以将属性作为"out"或"ref"参数传递,如果不是,为什么不呢?
例如
Person p = new Person();
Run Code Online (Sandbox Code Playgroud)
...
public void Test(out p.Name);
Run Code Online (Sandbox Code Playgroud) 如何比较Windows m/c的cmd提示符下的两个目录?我想要等同于UNIX的diff -r.
如果我有两个序列并且我想要将它们一起处理,我可以将它们联合起来然后我们去.
现在假设我有一个项目,我想在两个序列之间处理.我可以通过创建一个包含单个项目的数组来获取它,但是有更简洁的方法吗?即
var top = new string[] { "Crusty bread", "Mayonnaise" };
string filling = "BTL";
var bottom = new string[] { "Mayonnaise", "Crusty bread" };
// Will not compile, filling is a string, therefore is not Enumerable
//var sandwich = top.Union(filling).Union(bottom);
// Compiles and works, but feels grungy (looks like it might be smelly)
var sandwich = top.Union(new string[]{filling}).Union(bottom);
foreach (var item in sandwich)
Process(item);
Run Code Online (Sandbox Code Playgroud)
是否有批准的方式,或者这是批准的方式?
谢谢
通过文本格式我意味着更复杂的东西.
起初我开始手动将我问这个问题的文本文件中的5000行添加到我的项目中.
文本文件有5000行,长度不同.例如:
1 1 ITEM_ETC_GOLD_01 ??(?) xxx xxx xxx_TT_DESC 0 0 3 3 5 0 180000 3 0 1 0 0 255 1 1 0 0 0 0 0 0 0 0 0 0 -1 0 -1 0 -1 0 -1 0 -1 0 0 0 0 0 0 0 100 0 0 0 xxx item\etc\drop_ch_money_small.bsr xxx xxx xxx 0 2 0 0 1 0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 …
Run Code Online (Sandbox Code Playgroud) 我有一个日历,它将选定日期作为字符串传递给方法.在此方法中,我想生成一个列表,其中包含从所选开始日期开始到所选结束日期的所有日期,显然包括所有日期,无论在所选开始日期和结束日期之间有多少天.
下面我有方法的开头,它接受日期字符串并将它们转换为DateTime变量,以便我可以使用DateTime计算函数.但是,我似乎无法计算出如何计算开始日期和结束日期之间的所有日期?显然,第一阶段是从结束日期中减去开始日期,但我无法计算其余步骤.
非常感谢,
亲切的问候.
public void DTCalculations()
{
List<string> calculatedDates = new List<string>();
string startDate = "2009-07-27";
string endDate = "2009-07-29";
//Convert to DateTime variables
DateTime start = DateTime.Parse(startDate);
DateTime end = DateTime.Parse(endDate);
//Calculate difference between start and end date.
TimeSpan difference = end.Subtract(start);
//Generate list of dates beginning at start date and ending at end date.
//ToDo:
}
Run Code Online (Sandbox Code Playgroud)