C#でストリング比較関数(CompareTo)実行結果をメモします。
string teststring = "20101115";
System.Diagnostics.Debug.WriteLine(teststring.CompareTo("20101114"));
System.Diagnostics.Debug.WriteLine(teststring.CompareTo("20101115"));
System.Diagnostics.Debug.WriteLine(teststring.CompareTo("20101116"));
実行結果:
1
0
-1
また
string teststring = "20101115";
System.Diagnostics.Debug.WriteLine("20101113".CompareTo(teststring));
System.Diagnostics.Debug.WriteLine("20101114".CompareTo(teststring));
System.Diagnostics.Debug.WriteLine("20101115".CompareTo(teststring));
System.Diagnostics.Debug.WriteLine("20101116".CompareTo(teststring));
System.Diagnostics.Debug.WriteLine("20101117".CompareTo(teststring));
実行結果:
-1
-1
0
1
1
自分で作ったり提供したりするものは、まず自分自身で使ってみろろということです。自分じゃ使わないものなら人はいくらでも無責任にも無思考にもなれる。そういう投げやりな「サービス」やら「プロダクツ」なんて、だれだってイヤだ。自分が作り手と同時に利用者の立場になれば、ちゃんと使えるレベルのものを提供しようとします。
2010年11月19日金曜日
2010年10月31日日曜日
WCF勉強開始
Windows Communication Foundation(WCF)は、.NET Framework 3.0 における新しい通信サブシステムであり、アプリケーション同士をネットワーク経由で接続する仕組みである。Indigo とも呼ばれていた。WCF アプリケーションは .NET でサポートされている言語なら、どの言語でも開発できる。
IT人としてこのWCF技術を勉強しないと、時代に遅れるでしょう。
IT人としてこのWCF技術を勉強しないと、時代に遅れるでしょう。
2010年8月26日木曜日
UpdatePanel使用コツ
①クライアントのjavascriptを実行する
private void RunClientScript(string key, string content)
{
ScriptManager.RegisterClientScriptBlock(UpdatePanelGridView, typeof(UpdatePanel), key, content, true);
}
②PageLoadイベントに非同期リクエストかどうかを判断する
ScriptManager170.IsInAsyncPostBack
private void RunClientScript(string key, string content)
{
ScriptManager.RegisterClientScriptBlock(UpdatePanelGridView, typeof(UpdatePanel), key, content, true);
}
②PageLoadイベントに非同期リクエストかどうかを判断する
ScriptManager170.IsInAsyncPostBack
2010年8月19日木曜日
lambda式サンプル
C#3.0からlambda式文法が提供されました、ここでlambda式使用方法を紹介します。
関数定義:
private int test01(int p1, Func<int, int> func1)
{
return func1(p1);
}
この関数の第二引数は一つのint引数とint戻り値の関数式を指定しています。
lambda文法使用例:
int temp = 0;
temp = test01(5, x => x * x); // 25
temp = test01(5, x => x + x); // 10
temp = test01(5, x => x - x); // 0
関数定義:
private int test01(int p1, Func<int, int> func1)
{
return func1(p1);
}
この関数の第二引数は一つのint引数とint戻り値の関数式を指定しています。
lambda文法使用例:
int temp = 0;
temp = test01(5, x => x * x); // 25
temp = test01(5, x => x + x); // 10
temp = test01(5, x => x - x); // 0
2010年7月15日木曜日
Linq-GroupBy
Linq言語のGroupBy機能を紹介します。
従来のSELECT文でGroupByをしていますが、Linq言語を利用したら簡単にできるようになりました、本当にありがたい技術です。
class Pet
{
public string Name { get; set; }
public int Age { get; set; }
}
// Uses method-based query syntax.
public static void GroupByEx1()
{
// Create a list of pets.
List<Pet> pets =
new List<Pet>{ new Pet { Name="Barley", Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 },
new Pet { Name="Daisy", Age=4 } };
// Group the pets using Age as the key value
// and selecting only the pet's Name for each value.
IEnumerable<IGrouping<int, string>> query =
pets.GroupBy(pet => pet.Age, pet => pet.Name);
// Iterate over each IGrouping in the collection.
foreach (IGrouping<int, string> petGroup in query)
{
// Print the key value of the IGrouping.
Console.WriteLine(petGroup.Key);
// Iterate over each value in the
// IGrouping and print the value.
foreach (string name in petGroup)
Console.WriteLine(" {0}", name);
}
}
従来のSELECT文でGroupByをしていますが、Linq言語を利用したら簡単にできるようになりました、本当にありがたい技術です。
class Pet
{
public string Name { get; set; }
public int Age { get; set; }
}
// Uses method-based query syntax.
public static void GroupByEx1()
{
// Create a list of pets.
List<Pet> pets =
new List<Pet>{ new Pet { Name="Barley", Age=8 },
new Pet { Name="Boots", Age=4 },
new Pet { Name="Whiskers", Age=1 },
new Pet { Name="Daisy", Age=4 } };
// Group the pets using Age as the key value
// and selecting only the pet's Name for each value.
IEnumerable<IGrouping<int, string>> query =
pets.GroupBy(pet => pet.Age, pet => pet.Name);
// Iterate over each IGrouping in the collection.
foreach (IGrouping<int, string> petGroup in query)
{
// Print the key value of the IGrouping.
Console.WriteLine(petGroup.Key);
// Iterate over each value in the
// IGrouping and print the value.
foreach (string name in petGroup)
Console.WriteLine(" {0}", name);
}
}
2010年7月12日月曜日
Linq文法でExcelプロセスメモリを解放する
public static void ReleaseExcelMemoryResource()
{
System.Diagnostics.Process[] aobjProcessExcel =
System.Diagnostics.Process.GetProcessesByName("excel");
var LinqExcelProess = from excelprocess in aobjProcessExcel
orderby excelprocess.StartTime descending
select excelprocess;
LinqExcelProess.First().Kill();
}
2010年5月26日水曜日
登録:
コメント (Atom)