Skip to content

Instantly share code, notes, and snippets.

var dic = new Dictionary<string, int>
{
{"Level_01", 1},
{"Level_02", 2},
{"Level_03", 3},
{"Level_04", 3}
}
;
var x= dic.Select(kvp => new KeyValuePair<int, string>(kvp.Value, kvp.Key));
var y = dic.ToLookup(pair => pair.Value, pair => pair.Key);
void Main() {
List<string> list = new List<string>
{
"hi",
"hi"
};
IEnumerable<string> ienumrable = new List<string>
{
@onionmk2
onionmk2 / gist:97a593048f4efe1fcd48e3760bb7b73e
Created February 16, 2017 11:52 — forked from tany3/gist:2d032cbbbd9db04b976d
重複処理 IEnumerableをそのまま使い回さない - Possible multiple enumeration of IEnumerable

IEnumerableをそのまま使うと、使う度に毎回変換される。遅延実行。 http://confluence.jetbrains.com/display/ReSharper/Possible+multiple+enumeration+of+IEnumerable

Assuming that GetNames() returns an IEnumerable, we are, effectively, doing extra work by enumerating this collection twice in the two foreach statements. If GetNames() results in a database query, you end up doing that query twice, while both times getting the same data.

ということで、特に複数回使う場合など適宜ToList()やToArray()しておく。

参考:LINQ クエリの概要 (C#) http://msdn.microsoft.com/ja-jp/library/bb397906.aspx

@-moz-document url-prefix(https://docs.unity3d.com/) {
/*
this is perhaps only way to change color such as `<span style="color:red;"></span>public void `
*/
.sig-block {
color: #44A5CB;
}
.sig-block {
font-size: 1.25em;
@onionmk2
onionmk2 / c# class vs struct.md
Last active February 19, 2017 11:44
CS1612 Cannot modify the return value of 'UserQuery.ComplexUser.complex' because it is not a variable

class

no error.

void Main()
{

	//ok
	var ComplexUser = new ComplexUser();
	var complex = ComplexUser.complex;
	complex.Re = 1;
@onionmk2
onionmk2 / IEnumrableAndIEnumerator.cs
Last active February 20, 2017 15:02
How to implement IEnumrable and IEnumerator
using System;
using System.Collections;
internal class Program
{
private static void Main(string[] args)
{
var ints = new MyIEnumrable(0, 10);
foreach (var i in ints)
Console.WriteLine(i);
@onionmk2
onionmk2 / yield and foreach .cs
Last active February 20, 2017 15:15
yield and foreach
internal class Program
{
private static void Main(string[] args)
{
var ints = MyIEnumrable.FromTo(0, 10);
foreach (var i in ints)
Console.WriteLine("{0}", i);
}
}
using UnityEngine;
public class Test : MonoBehaviour
{
private void Start()
{
}
private void Update()
{
@onionmk2
onionmk2 / Coroutine.md
Last active April 26, 2017 15:08
Unity3D Coroutine. how to use StartCoroutine, WaitForSeconds, LoadSceneAsync...
@onionmk2
onionmk2 / Vector3operator *.md
Created February 22, 2017 11:44
Vector3.operator *