##重複処理 WhereとFirstOrDefault - Replace with single call to FirstOrDefault()
###変更前
collection.where(item => item.Equals(value)).FirstOrDefault();
###変更後
collection.FirstOrDefault(item => item.Equals(value));
##重複処理 WhereとFirstOrDefault - Replace with single call to FirstOrDefault()
###変更前
collection.where(item => item.Equals(value)).FirstOrDefault();
###変更後
collection.FirstOrDefault(item => item.Equals(value));
##カウントを取らなくてい - Use method Any() あるcollectionが0件であることを知りたいなら、!Any()を使う。 Any()は有無を返す。Count()は個数を返すので、数え上げ処理が動く。 ###変更前
if (collection.Count() == 0) { ... } else { ... }
###変更後
if (!collection.Any()) { ... } else { ... }
###仕様を明確にする - Field can be readonly 初期化時だけセットするフィールドはreadonlyにすることで、副作用を防ぐことができる(安全弁になる)。
public class Book
{
private string readonly name;
private int readonly ISBN;
public Book(string name, int isbn)
{
# Test data | |
## countries | |
Afghanistan | |
Albania | |
Algeria | |
Andorra | |
Angola | |
Antigua and Barbuda | |
Argentina |
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
using System; | |
using CSChatworkAPI; | |
namespace Example | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var client = new ChatworkClient(@"APIToken"); // TODO:APIToken |
# | |
#see http://melcher.it/2013/03/powershell-list-all-iis-webapplications-net-version-state-identity/ | |
# | |
try{ | |
Import-Module WebAdministration | |
Get-WebApplication | |
$webapps = Get-WebApplication | |
$list = @() | |
foreach ($webapp in get-childitem IIS:\AppPools\) |
# | |
#start web site | |
# | |
$targetSiteNames = ( "WebSite1", "WebSite2" ) | |
$targetAppPools = ( "AppPool1", "AppPool2" ) | |
"Settings.Target Sites:" | |
foreach ($name in $targetSiteNames) { "`t" + $name } | |
"Settings.Target AppPools:" | |
foreach ($name in $targetAppPools) { "`t" + $name } |
# | |
#stop web site | |
# | |
$targetSiteNames = ( "WebSite1", "WebSite2" ) | |
$targetAppPools = ( "AppPool1", "AppPool2" ) | |
"Settings.Target Sites:" | |
foreach ($name in $targetSiteNames) { "`t" + $name } | |
"Settings.Target AppPools:" | |
foreach ($name in $targetAppPools) { "`t" + $name } |
c:\Program Files\Oracle\VirtualBox>VBoxManage.exe clonehd "D:\src.vdi" "D:\dst.vdi" | |
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% | |
Clone hard disk created in format 'VDI'. UUID: **** | |
c:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd "D:\dst.vdi" --resize 153600 | |
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% |