Skip to content

Instantly share code, notes, and snippets.

// As we all know, the generic List<T> class in .NET doesn't
// have a RemoveMultiple method. Could you implement it for me?
// Say the elements are kept in the _items field, which is an
// array of type T. Also, use _count to keep the current number
// of elements.
// PS: You can compare two items with "==" operator.
namespace System.Collections.Generic
{
public class List<T>
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using BenchmarkDotNet.Attributes;
namespace Dict
{
public class DictionaryPerf
{
private Dictionary<int, int> _original;

打印表头

小明正在用JavaScript写一个日志分析程序。该程序会将日志转化为CSV文件,以便在Excel等应用中加载为一个表格。现在他在生成表头上遇到了困难。

他需要实现如下一个方法:

function printLine(array) {
    console.log(array.join(","));
}
namespace SimpleConsole
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main()
// Please write an sequence list implements the interface with the required
// time complexity described in the comments. The users can add the same
// element as many times as they want, but it doesn't support the null item.
// You can use any types in .NET BCL but cannot use any 3rd party libraries.
// PS: You don't need to consider the multi-threaded environment.
interface IMyList<T> : IEnumerable<T>
{
// O(1)
// Add an item at the beginning of the list.
void AddFirst(T item);
///////////////////////////////////////////////////////
// Talk is cheap. Show me the code. - Linus Torvalds
///////////////////////////////////////////////////////
public abstract class CalculatorBase : IDisposable {
protected void StartCore() {
// ...
}
namespace HashTableDict
{
using System.Collections;
using System.Collections.Generic;
public class Hashtable<TKey, TValue> : IDictionary<TKey, TValue>
where TKey : class
where TValue : class
{
private readonly Hashtable _ht = new Hashtable();
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Dynamic;
using System.Xml.Linq;
using System.Xml;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;
// 其实这题可以写的很简单,它的关键根本不是CAS操作。
// 使用一个标志(flag也好,status判断也罢)来避免Start和Dispose重入是很容易
// 想到的手段,很多同学也这么做了。大部分同学遇到的问题是:假如StartCore已经
// 启动,那么如何让Dispose方法等待其完成。有些同学用while (true),有些同学用
// 锁,但都避免不了让Dispose线程等待Start线程。
// 这里“避免等待”的关键在于要跳出思维界限:谁说DisposeCore方法一定要在Dispose
// 方法里执行的?我们就不能在Start里销毁对象吗?
struct MyKey {
private readonly int _a;
private readonly int _b;
public MyKey(int a, int b) {
_a = a;
_b = b;
}
}