如何在JavaScript中获取当前时间并在时间戳中使用它?
我试过var x = Date()了:
2012年5月15日星期二05:45:40 GMT-0500
但我只需要当前的时间,例如, 05:45
如何将其分配给变量?
最近,围绕.NET世界中所有不同的模拟框架进行了大量宣传.我还没有完全掌握它们的优点.编写我自己需要的模拟对象似乎并不难.特别是在Visual Studio的帮助下,我可以快速编写一个实现我想要模拟的接口的类(它为我自动生成几乎所有内容),然后为我的测试编写一个实现方法.完成!为什么要经历一个理解模拟框架的麻烦,其唯一目的是保存几行代码.或者是一个模拟框架,不仅仅是关于保存代码行?
我正在使用Entity Framework和Linq to Entitites.
我想知道Visual Studio 2012中是否有任何方法可以逐步调试此代码.在放置断点时,光标越过它但不会进入.
我更感兴趣的是看到xe的值..而不是例如生成的sql.
注意:我可以使用其他工具或Visual Studio插件.
IEnumerable<EventPushNotification> eventToPushCollage = eventsForEvaluation
.GroupJoin(eventCustomRepository.FindAllPushedEvents(),
e => e.Id,
p => p.PushedEventId,
(e, p) => new { e, p })
.Where(x => x.e.DateTimeStart > currentDateTime &&
currentDateTime >= x.e.DateTimeStart.AddMinutes(defaultReminders) && // Data from default reminder for collage event in web.config
x.p.Count() == 0) // Check if the Event has not being already pushed
.Select(y => new EventPushNotification
{
Id = y.e.Id,
EventTitle = y.e.EventTitle,
DateTimeStart = y.e.DateTimeStart,
DateTimeEnd = y.e.DateTimeEnd,
Location …Run Code Online (Sandbox Code Playgroud) 如果我有一个返回某个集合的方法的接口,是否可以返回集合类型的实现?
例如:
public interface IVehicle
{
IEnumerable<Part> GetParts(int id);
}
public class Car : IVehicle
{
List<Part> GetParts(int id)
{
//return list of car parts
}
}
public class Train : IVehicle
{
IEnumerable<Part> GetParts(int id)
{
//return IEnumerable of train parts
}
}
Run Code Online (Sandbox Code Playgroud)
如果没有,为什么不呢?
至少对我而言,这是有道理的.
我有一种情况,需要检查txt文件是否存在,如果不存在,则需要创建它。
在此之后,我需要立即用一些文本填充文件。
这是我的代码如下所示:
if (!File.Exists(_filePath))
{
File.Create(_filePath);
}
using (var streamWriter = File.AppendText(_filePath))
{
//Write to file
}
Run Code Online (Sandbox Code Playgroud)
System.IO.IOException仅在必须创建新文件时,我在第5行收到异常()。这是例外:
The process cannot access the file '**redacted file path**' because it is being used by another process.
我不想添加Thread.Sleep(1000);,因为这是一个糟糕的解决方案。
有没有办法找出何时该文件再次可用,以便我可以对其进行写入?
c# ×3
collections ×1
datetime ×1
debugging ×1
file ×1
ienumerable ×1
interface ×1
javascript ×1
lambda ×1
linq ×1
mocking ×1
oop ×1
streamwriter ×1
unit-testing ×1