- - PR -
C#de
1
投稿者 | 投稿内容 |
---|---|
|
投稿日時: 2008-10-29 19:35
言語:VisualStdio2008 C#
下のソースのメンバ関数の中で定義している//ここから〜//ここまでの処理を コンストラクトの中で定義したのですが、どのような記述にしたらいいのでしょうか? dtc変数とかは、各メソッドで使用したいと思っています。 どなたかすみませんが教えてください。宜しくお願いします。 namespace DBAccessLib { public class DBClass{ // コンストラクト static DBClass(){ // ここに(//ここから〜//ここまで)の内容定義したい } public static void AddToDatabase(IEnumerable list){ // ここから string ConnectStr = "Data Source=ART001; Initial Catalog=pubs; Integrated Security=True"; DataClassesDataContext dtc = new DataClassesDataContext(ConnectStr); // ここまで } public static void UpdateToDatabase(IEnumerable list){ // 上記と同じ定義 string ConnectStr = "Data Source=ART001; Initial Catalog=pubs; Integrated Security=True"; DataClassesDataContext dtc = new DataClassesDataContext(ConnectStr); } } |
|
投稿日時: 2008-11-12 10:25
//ここから〜//ここまでの処理を static なコンストラクタに書いて、
dtc を static 変数にすれば、各メソッドで使いまわせます。 |
|
投稿日時: 2008-11-12 10:47
なかむら様、ありがとうございます。
|
|
投稿日時: 2008-11-12 12:39
誘導
http://www.atmarkit.co.jp/bbs/phpBB/viewtopic.php?topic=47033&forum=7 _________________ C# と VB.NET の入門サイト じゃんぬねっと日誌 |
1