是否List<T>
始终保证项目将按枚举时添加的顺序返回?
更新:感谢所有人的回答,让我放心.我List<T>
用.NET Reflector快速戳了一下这个类(应该首先应该这样做),实际上底层存储是T
(T[]
)的数组.
那么您认为防止C#Windows服务的多个线程同时运行的最佳方法是什么(该服务是否使用了timer
该OnElapsed
事件)?
使用lock()
或mutex
?
我似乎无法掌握这个概念mutex
,但使用lock()
似乎对我的情况很好.
我是否应该花时间学习如何使用mutex
?
我正在使用不同版本的Windows的一堆计算机上测试JPEG解压缩.所有这些计算机都安装了.NET 4,我正在编译.NET 2和"任何CPU"平台目标.以下代码在不同系统上生成不同的输出.
Bitmap bmp = (Bitmap)Image.FromFile("test.jpg");
long datasum = 0;
for (int y = 0; y < bmp.Height; y++)
for (int x = 0; x < bmp.Width; x++)
datasum = datasum + bmp.GetPixel(x, y).R + bmp.GetPixel(x, y).G + bmp.GetPixel(x, y).B;
Console.WriteLine(datasum);
Run Code Online (Sandbox Code Playgroud)
所有Win7 64位和WinXP 32位机器都产生一个结果.所有Win7 32位机器都产生了另一个结果.
任何想法为什么输出会有所不同?
我试图将BitmapSource的一部分复制到WritableBitmap.
到目前为止这是我的代码:
var bmp = image.Source as BitmapSource;
var row = new WriteableBitmap(bmp.PixelWidth, bottom - top, bmp.DpiX, bmp.DpiY, bmp.Format, bmp.Palette);
row.Lock();
bmp.CopyPixels(new Int32Rect(top, 0, bmp.PixelWidth, bottom - top), row.BackBuffer, row.PixelHeight * row.BackBufferStride, row.BackBufferStride);
row.AddDirtyRect(new Int32Rect(0, 0, row.PixelWidth, row.PixelHeight));
row.Unlock();
Run Code Online (Sandbox Code Playgroud)
我得到"ArgumentException:值不在预期的范围内." 在线CopyPixels
.
我试着换row.PixelHeight * row.BackBufferStride
用row.PixelHeight * row.PixelWidth
,但后来我得到一个错误说价值太低.
我找不到使用这个重载的单个代码示例CopyPixels
,所以我正在寻求帮助.
谢谢!
我正在使用Kinect for Windows SDK来创建一个用于执行的应用程序(使用C#).
基本上我需要跟踪指挥的一只手(通常是右手)并识别他的指挥速度(BPM)以通过MIDI将该值发送到另一个应用程序.
我开始是SkeletonFramesReadyEvent
添加JointType.HandRight
了DateTime.Now.Ticks
时间戳历史List
被更新和删除中的第一项.我保持60帧(2秒)的历史.
我通过搜索最后的低点和高点计算BPM Joint.Position.Y
,然后计算差值和除法bpm = 60*ticksPerSecond/diff
.但结果是错误的.还有另一种方法吗?我错过了什么?
这是我到目前为止使用的:
public int DetectBPM(JointType type)
{
// we have not history yet
if (!HasHistory()) return 0;
// only calculate every second
var detectTime = DateTime.Now.Second;
if (_lastBPM != 0 && _lastBPMDectect == detectTime) return _lastBPM;
// search last high/low boundaries
var index = (int) type;
var list = History[index];
var i = list.Count - 1;
var lastHigh = list[i]; …
Run Code Online (Sandbox Code Playgroud) 我总是看到其他人生成如下代码:
var smtp = new SmtpClient();
但为什么要使用var
而不是SmtpClient
在这种情况下呢?我总是用
SmtpClient smtp = new SmtpClient();
是var
更有效?为什么要使用var
而不是实际的变量类型?我错过了什么吗?
new
构造函数和new
成员声明之间有什么区别?
例
public class PspGame {
private List<string>name = new List<string>();
private List<string>_value;
public PspGame() {
_value = new List<string>();
}
}
Run Code Online (Sandbox Code Playgroud)
最好的方法是什么,是否有任何性能问题?
我敢打赌,这是一个非常普遍的问题,我认为这个问题无法解决,但至少我会尝试.
检查此图片:
请访问以下URL以获取更大的图像:http://i.imgur.com/nHPNr.jpg
HTML代码:
<div style="font-family: Arial, sans-serif; font-size: 60px; letter-spacing: 0px; padding: 0; margin: 0;">TEXT GOES HERE</div>
Run Code Online (Sandbox Code Playgroud)
如您所见,字体看起来不一样.有什么方法可以解决这个问题吗?
有任何想法吗?
我有一个认可项目.它工作,但如果我使用这个项目如何一个类和从其他类调用其方法我有一个问题在线异常:
sre = new SpeechRecognitionEngine(ri.Id);
Run Code Online (Sandbox Code Playgroud)
错误是:
找不到所需ID的识别器.
代码:
KinectAudioSource source = kinectSensor.AudioSource;
source.EchoCancellationMode = EchoCancellationMode.None; // No AEC for this sample
source.AutomaticGainControlEnabled = false; // Important to turn this off for speech recognition
// source.SystemMode = SystemMode.OptibeamArrayOnly;
speechRecognizer = CreateSpeechRecognizer();
using (Stream s = source.Start())
{
speechRecognizer.SetInputToAudioStream(s, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
Console.WriteLine("Recognizing speech. Say: 'purple', 'green' or 'blue'. Press ENTER to stop");
speechRecognizer.RecognizeAsync(RecognizeMode.Multiple);
Console.ReadLine();
Console.WriteLine("Stopping recognizer ...");
speechRecognizer.RecognizeAsyncStop();
}
private static SpeechRecognitionEngine CreateSpeechRecognizer()
{
RecognizerInfo ri …
Run Code Online (Sandbox Code Playgroud)