Skip to content

Instantly share code, notes, and snippets.

var subArray = new int[BUFFER_SIZE];
for (int i = 0; i < Data.Length - (BUFFER_SIZE + 1); i += BUFFER_SIZE)
{
Array.Copy(Data, i, subArray, 0, BUFFER_SIZE);
if (subArray[subArray.Length - 1] != i + BUFFER_SIZE - 1)
throw new Exception(); // avoid optimization
}
var spanData = new Span<int>(Data);
for (int i = 0; i < Data.Length - (BUFFER_SIZE + 1); i += BUFFER_SIZE)
{
var subSpan = spanData.Slice(i, BUFFER_SIZE);
if (subSpan[BUFFER_SIZE - 1] != i + BUFFER_SIZE - 1)
throw new Exception();
}
fixed (int* data = &Data[0])
{
for (int i = 0; i < Data.Length - (BUFFER_SIZE + 1); i += BUFFER_SIZE)
{
int* sub = data + i;
if (sub[BUFFER_SIZE - 1] != i + BUFFER_SIZE - 1)
throw new Exception();
}
}
IntPtr pdata = Marshal.AllocHGlobal(Data.Length * sizeof(int));
int* data = (int*)pdata;
try
{
Marshal.Copy(Data, 0, pdata, Data.Length);
for (int i = 0; i < Data.Length - (BUFFER_SIZE + 1); i += BUFFER_SIZE)
{
int* sub = data + i;
if (sub[BUFFER_SIZE - 1] != i + BUFFER_SIZE - 1)
public interface IAsyncObserver<in T>
{
Task OnNextAsync(T value);
Task OnErrorAsync(Exception error);
Task OnCompletedAsync();
}
Task<IAsyncDisposable> SubscribeAsync(IAsyncObserver<T> observer);
using System.Reactive.Observable.Aliases;
// filter will invoke where
Observable.Range(0, 10).Filter(i => i % 2 == 0);
Observable.Range(0, 10).Where(i => i % 2 == 0);
// map will invoke select
Observable.Range(0, 10).Map(i => $"- {i} -");
Observable.Range(0, 10).Select(i => $"- {i} -");
public static IObservable<TSource> Filter<TSource>(
this IObservable<TSource> source,
Func<TSource, bool> predicate)
{
return source.Where<TSource>(predicate);
}
private static async Task Exec()
{
try
{
await Task.Delay(1);
await A();
}
catch (Exception ex)
{
Trace.WriteLine(ex);
private static async Task Exec()
{
try
{
await Task.Delay(1);
await A();
}
catch (Exception ex)
{
Trace.WriteLine(ex.Format());