我正在尝试创建一个将使用重复数据的数组数组,如下所示:
int[] list1 = new int[4] { 1, 2, 3, 4 };
int[] list2 = new int[4] { 5, 6, 7, 8 };
int[] list3 = new int[4] { 1, 3, 2, 1 };
int[] list4 = new int[4] { 5, 4, 3, 2 };
int[,] lists = new int[4, 4] { list1 , list2 , list3 , list4 };
Run Code Online (Sandbox Code Playgroud)
我无法让它发挥作用,我想知道我是否接近这个错误.
我正在尝试做的是创建一些方法来创建一个长列表,如果值,所以我可以重复地按特定顺序处理它们.就像是,
int[,] lists = new int[90,4] { list1, list1, list3, list1, list2, (and so on)};
for (int i = …Run Code Online (Sandbox Code Playgroud) 我刚刚将我的MongoDB从2.5.0更新到2.7.0.Visual Studio告诉我,当我想创建这样的索引时:
protected override Task OnPerformMaintenanceAsync(CancellationToken cancellationToken) =>
NotificationLogs.Indexes.CreateOneAsync(Builders<NotificationLog>.IndexKeys.Ascending(_ => _.TimestampUtc));
Run Code Online (Sandbox Code Playgroud)
已经过时了.他们希望我们使用CreateIndexModel https://mongodb.github.io/mongo-csharp-driver/2.6/apidocs/html/T_MongoDB_Driver_CreateIndexModel_1.htm
唯一的问题是我找不到一个能够实现同样功能的例子.
我试过了:
protected Task OnPerformMaintenanceTestAsync(CancellationToken cancellationToken)
{
// Old approach
// var builder = Builders<NotificationLog>.IndexKeys.Ascending(x => x.TimestampUtc);
// New approach
var indexModel = new CreateIndexModel<NotificationLog>(nameof(NotificationLog.TimestampUtc));
return NotificationLogs.Indexes.CreateOneAsync(indexModel);
}
Run Code Online (Sandbox Code Playgroud)
我一直得到以下异常:
System.FormatException: 'JSON reader was expecting a value but found 'TimestampUtc'.'
我正在.NET Core中为旧的照明控制台开发接口,目前正在实现数据包。此接口/ API的基本思想如下:客户端在一个UDP端口上发送其数据包,并且控制台以错误代码响应。控制台通过另一个UDP端口发送其数据包。
因此,在设计API时,我只是使用了Action<ErrorCode>作为回调函数。但是,当一次处理多个数据包时,此方法不是很实用。
我的UdpClient收到数据包时引发一个事件,但控制台返回的错误代码不超过4字节。
所以我已经尝试过使用SemaphoreSlim。
我的想法是让发送方等到事件发生并释放信号量。问题基本上是,这是处理此问题的最快,最“干净”的方法:
// The Event-Callback:
private void Sender_Recieve(object sender, ErrorCode e)
{
lastError = e;
semaphore.Release();
}
// The SendPacket method:
public async Task<ErrorCode> SendPacketAsync(Packet packet)
{
// send packet
await semaphore.WaitAsync();
return lastError;
}
Run Code Online (Sandbox Code Playgroud)
那么,有什么方法可以更快/更好地做到这一点而又不会降低性能?
为什么在C系列语言中,当我们对任何循环使用计数器时,最优选的比较是Greater Equal To <=反转?请看看这三段代码
for (var i = 0; i <= 5; i++)
{...}/// loop1
for (var i = 0; i < 6; i++)
{...}/// loop2
for (var i = 0; i != 6; i++)
{...}/// loop3
Run Code Online (Sandbox Code Playgroud)
我理解为什么不鼓励循环3,因为代码中的某些东西可以分配i > 5导致无限循环.但是loop1并且loop2基本上是相同的,并且loop2可能是更好的性能,因为只进行了一次比较.那么为什么loop1更优选.它只是惯例还是还有更多东西?
注意:我没有正式的编程培训.当我需要更好的工具来编程8051而不是使用汇编语言时,我只是选择了C.
/* Program to search a character in a sentence and tell the occurrence of
that character in that sentence and also prints all the indexes. */
package com.shobhit.string1;
import java.util.Scanner;
public class StringSearch1
{
public static void main(String args[])
{
String sentence;
char c; // takes first character of input
char duplicate; // finds duplicates of c in code
int length; // find sentence length
int index; // index of character in sentence
int numberOfOccurrence = 0;
Scanner in = …Run Code Online (Sandbox Code Playgroud) 我有下面的递归方法正在工作,我似乎无法打破它:
public static void smsMessage(string message, int maxLength)
{
int strPos = 0;
var spaces = message.ToCharArray()
.Select((v, x) => new { value = v, index = x })
.Where(element => !char.IsLetterOrDigit(element.value))
.Select(element => element.index)
.ToList();
for (int i = 0; i < spaces.Count; ++i)
{
strPos += spaces[i];
if (strPos >= maxLength || i == spaces.Count - 1 )
{
if (i == spaces.Count-1)
{
strPos -= spaces[i];
returnMessage.Add(message.Substring(0).Trim());
return;
}
strPos -= spaces[i];
returnMessage.Add(message.Substring(0, spaces[i - 1]).Trim());
message …Run Code Online (Sandbox Code Playgroud)