This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Company : IFormattable | |
{ | |
// プロパティは省略。 | |
public string ToString(string format, IFormatProvider formatProvider) | |
{ | |
if (format == null || format == "G" || format == "f") { | |
return CompnayName; | |
} | |
if (format == "s") { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cultures = new[] { "ja-jp", "zh-cn", "en-us", "en-gb", "fr-fr", "de-de", "pt-br", "tr-tr", "he-il" }; | |
var price = 9800; | |
foreach (var c in cultures) | |
{ | |
var culture = new CultureInfo(c); | |
var plus = price.ToString("c", culture); | |
var minus = (-price).ToString("c", culture); | |
Console.WriteLine("{0,-11} / {1,-12} ({2})", plus, minus, culture.DisplayName); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Task<IEnumerable<T>> ExecuteAsync<T>(this DataServiceQuery<T> q) | |
{ | |
return Task.Factory.FromAsync<IEnumerable<T>>(q.BeginExecute, q.EndExecute, null); | |
} | |
var tasks = Common.GetQueries(context, keys) | |
.Select(x => x.ExecuteAsync() | |
.ContinueWith(t => { lock (w) Common.Output(t.Result, w); }) | |
).ToArray(); // ToArray を付けて、ここで全タスクを先に起動してしまう。 | |
Task.WaitAll(tasks.ToArray()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var text = new WebClient().DownloadString(@"http://hogehoge.org"); | |
var q = | |
from Match m in Regex.Matches(text, @"href=""(?<url>.*?)""") | |
where m.Success | |
select m.Groups["url"]; | |
foreach (var x in q) | |
{ | |
Console.WriteLine("URL: {0}", x); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Drawing; | |
using System.Windows.Forms; | |
class MyForm : Form | |
{ | |
static void Main() | |
{ | |
Application.Run( new MyForm() ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
boolean isSame; | |
// (例1) | |
Integer value1 = new Integer(100); | |
Integer value2 = new Integer(100); | |
isSame = value1.equals(value2); // true | |
isSame = (value1 == value2); // false | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String path = "C:/dir/to/my/file/myfile.txt"; | |
String encoding = "Windows-31j"; | |
// 入力ストリームを開く | |
BufferedReader reader = new BufferedReader( | |
new InputStreamReader(new FileInputStream(path), encoding)); | |
// 1行ずつ読み込んで、標準出力へ書き出す | |
String line; | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String path = "C:/dir/to/my/file/myfile.txt"; | |
String encoding = "Windows-31j"; | |
// 出力ストリームを開く | |
PrintWriter writer = new PrintWriter( | |
new OutputStreamWriter(new FileOutputStream(path), encoding)); | |
// ファイルへ文字列を書き出す | |
try { | |
writer.println("This is test."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ドライバクラスのロード | |
Class.forName("oracle.jdbc.OracleDriver"); | |
// DBとの接続 | |
String url = "jdbc:oracle:thin:@dbhost:1521:sid"; | |
String user = "dbuser"; | |
String password = "dbpassword"; | |
Connection conn = DriverManager.getConnection(url, user, password); | |
String sql = "select ID, NAME from SHAIN"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ドライバクラスのロード | |
Class.forName("oracle.jdbc.OracleDriver"); | |
// DBとの接続 | |
String url = "jdbc:oracle:thin:@dbhost:1521:sid"; | |
String user = "dbuser"; | |
String password = "dbpassword"; | |
Connection conn = DriverManager.getConnection(url, user, password); | |
conn.setAutoCommit(false); // オートコミットをOFFにする |
OlderNewer