2009年8月25日火曜日

コレクションの列挙(IEnumerable, IEnumerator)

http://smdn.invisiblefulmoon.net/programming/netfx2/overview/enumeration/
App.path の代替
configfile = My.Application.Info.DirectoryPath & "\config.txt"
http://iijima.auemath.aichi-edu.ac.jp/pw/programming/pukiwiki.php?VB6%A2%AAVB2008
VB.NET: ByRef パラメータにリテラル値を渡す
http://homepage1.nifty.com/rucio/main/dotnet/shokyu/standard48.htm
PDF以外のソフト
http://homepage3.nifty.com/e-papy/o1.html#s3
ファイルのプロパティ→BuildAction プロパティ
http://msdn.microsoft.com/ja-jp/library/0c6xyb66(VS.80).aspx
Visual SourceSafe6.0 < Visual SourceSafe2005
AndAlsoとOrElse
Microsoft.Office.Interop.Excel.dll→Office PIAである(Officeインストール時インストールことができる)
Dim chA As Char→vb.netではCharの使用方法
chA = "A"c
C#:n=a>b?a:b;
b, a, b) ">vb.net:n = If(a > b, a, b)
例外処理
http://architect360.apricot-jp.com/300/post_20.html
例外は基本的にシステムのエントリポイント(アプリケーションを起動するところ)で捕捉し、例外が発生したらそれ以降の処理は中断して画面にメッセージを表示する
例外が発生してもリトライ、スキップ、修正など特別な処理を行う場合は、例外が発生する可能性がある箇所にTry~Catch句を書き、その例外が発生した時の処理をCatch句の中に書く。
//メッセージ表示
System.Windows.Forms.MessageBox.Show(e.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Stop);
ListViewコントロール
http://akademeia.info/index.php?VB.NET%2F%A5%B5%A5%F3%A5%D7%A5%EB%2F%A5%B3%A5%F3%A5%C8%A5%ED%A1%BC%A5%EB%2FListView
http://www.atmarkit.co.jp/fdotnet/dotnettips/258listviewadd/listviewadd.html
RichTextBoxコントロールのフォント設定について
https://www.grapecity.com/japan/support/search/faqcontent.asp?id=24117
String.split()
デフォールトではCharで区切る。直接ストリングを入れたら、""(0)→ストリングの先頭Charで区切る
String.split(new String(){""},None/Remove)→Removeの場合、空の文字列を含む配列要素が格納されません。
Strings.Split(input string,String)→文字列でも区切られる。
s1 = System.Text.RegularExpressions.Regex.Split(strText, "\r\n");
String.Trim
Charでトリムする。あるいはCharの配列、全て削除する。
直接ストリングを入れたら、""(0)→ストリングの先頭Charしか削除しない。
正しいシグネチャを持つ、アクセス可能な 'Main' メソッドは、'' に見つかりませんでした。
プロジェクトに Public Sub Main プロシージャを定義します。クラス内で定義する場合にだけ Shared として宣言します。
JAG配列
http://www.asahi-net.or.jp/~ef2o-inue/vbnet/sub13_09_010.html
http://d.hatena.ne.jp/fyts/20071104/array
structureとclass
①structures are value typed where as classes are refernce typed
②Class can be inherited But Structure can't be inherited
③In structures we cannot initilase the variable during the declaration while in classes we can
http://msdn.microsoft.com/ja-jp/library/2hkbth2a(VS.80).aspx
List/ArrayListのコピー
Listの格納したオブジェクト関係がある。Valueタイプなら、List.Cloneができる。Refタイプなら、List.Cloneできない。
命名は明確的、意味がわかりやすくて
例え、InfoContainer→Containerは容器の意味である、Form、Panelみたいなもの
Collection→集合の意味である、だれの属性として使っている。例え、table.Rows→Collection
Collectionを実装するとImplements Ienumerableが必要である。
例え、Class A Inherits ArrayList→クラス本来はArrayListである、クラス内に他のArrayListの定義は必要ない。
コントロールTag プロパティ
http://msdn.microsoft.com/ja-jp/library/system.windows.forms.control.tag.aspx
dictionary とhastable、hashset違う
http://tenmon.g.hatena.ne.jp/waka0529/20090203/1233642871
区別:
①この場合は KeyNotFoundException がはしる。
HashTable クラスを使用した場合、Dictionary とは違ってエラーを返さず null となる。
②hastableで検索が早い
③dc(key)戻り値はvalueのタイプ、ht(key)の戻り値はobject
同点:
①keyとValueの形式にデータを保存する.key重複できない、keyはnullできない
// Dictionaryクラスによる単語テーブル
Dictionary dictTable
= new Dictionary();
// 単語が未登録なら追加してから表示
if (!dictTable.ContainsKey(word)) {
dictTable.Add(word, null);
Console.WriteLine(word);
}
}
// HashSetクラスによる単語テーブル
HashSet hsTable = new HashSet();
foreach (string word in lincoln.Split(' ')) {
// 単語を追加。未登録なら表示
if (hsTable.Add(word)) {
Console.WriteLine(word);
}
Visual Studio 2005ウィンドウ
Visual Studio 2005 コマンドウィンドウ
http://wikiwiki.jp/hirase/?Visual%20Studio%202005%20%A5%B3%A5%DE%A5%F3%A5%C9%A5%A6%A5%A3%A5%F3%A5%C9%A5%A6
オブジェクトブラウザ
クラスビュー
ドキュメントアウトライン
できるだけ、更新、実行前にチェック処理を行う。OKだったら次の処理をする。
開発すると向こうの環境を考えて、できるだけ最新Framework3.0/3.5をやめる。
二重起動を防止する
①Mutexを利用する
②既存のウィンドウを最前面に移動する。→user32.dllのSetForegroundWindow(Inptr hwnd)
③vb.net→Me.IsSingleInstance=true
Imeを利用して、文字を変換する
①Imm32.dllのImmGetCompsitionString、ImmGetConversionList
②WordBreaker、WordSplit
メッセージ キューに現在ある Windows メッセージをすべて処理します。
Windows フォームを実行すると、新しいフォームが作成され、フォームはイベントが処理されるまで待機します。
フォームがイベントを処理するたびに、イベントに関連付けられたコードがすべて処理されます。
My.Application.DoEvents()
'ディレクトリのコピー(ディレクトリの属性の維持)
Dim Attr As IO.FileAttributes = IO.File.GetAttributes(sourceDirectory)
My.Computer.FileSystem.CopyDirectory(sourceDirectory, destDirectory)
IO.File.SetAttributes(destDirectory, Attr)
プロセスの戻り値
'*******************************************************************
'機能: 標準のShell関数では拾えない戻り値を得る
'引数: Program = 実行プログラム
'   Argument = 引数(ないときは"")
'   TimeOut = タイムオウト(0>ミリ秒、0<=タイムアウトしない)
'   WaitFlag = 待機フラグ(True:終了まで待機する、False:待機しない)
'   Val = 戻り値(コンソールに出力した文字列)
'戻値: 終了コード
'*******************************************************************
Public Function ShellStart(ByVal Program As String, _
ByVal Argument As String, _
ByVal TimeOut As Integer, _
ByVal WaitFlag As Boolean, _
ByRef Val As String) As Integer
Dim exitCode As Integer = -1
Dim pID As Integer
Dim psi As New Diagnostics.ProcessStartInfo
Dim proc As Diagnostics.Process = Nothing
Try
psi.FileName = Program
psi.Arguments = Argument
psi.CreateNoWindow = True
psi.UseShellExecute = False
psi.RedirectStandardOutput = True
proc = Diagnostics.Process.Start(psi)
pID = proc.Id
'プロセスの戻り値
Val = proc.StandardOutput.ReadToEnd
If TimeOut > 0 Then
proc.WaitForExit(TimeOut)
Else
proc.WaitForExit()
End If
If proc.HasExited Then
exitCode = proc.ExitCode
End If
Catch ex As Exception
Throw ex
Finally
If Not proc Is Nothing Then
proc.Dispose()
End If
End Try
Return exitCode
End Function
Assemblyを利用して、dllのメソッドを呼び出す
Public Shared Function InvokeDll(ByVal Path As String, _
ByVal ClassName As String, _
ByVal Method As String, _
ByVal ParamArray Params() As String) As Object
Dim assem As Assembly
Dim obj As Object
Dim t As Type
Dim ms() As MethodInfo
Dim out As Object = Nothing
assem = Assembly.Load(Path)
obj = assem.CreateInstance(Path & "." & ClassName)
t = obj.GetType()
ms = t.GetMethods()
For Each m In ms
If m.Name.Equals(Method) Then
out = m.Invoke(obj, New Object() {Params})
End If
Next
Return out
End Function

2009年8月13日木曜日

圣殿祭司的ASP.NET 2.0开发详解使用C#
C#设计模式
http://222.241.95.104/softii/C3sjmspdf.rar?0000000951784822099tflag=1250405004opin=3a39db9ecb9fc439ea656d75cca8f6d7&ip=.rar

ftp://221.238.195.3/uploads/computer/圣殿祭司的ASP.NET2.0开发详解_使用CS%5Bwww.TopSage.com%5D.zip

2009年8月11日火曜日

2009年8月9日日曜日

インタフェースと抽象クラス

インタフェース:
http://ufcpp.net/study/csharp/oo_interface.html
問題集:
http://ufcpp.net/study/csharp/exercise.html#ex_if1

抽象クラス
http://ufcpp.net/study/csharp/oo_abstract.html

抽象クラスとインターフェイスの違い
抽象クラスとインターフェイスは、派生クラスで実装するという点で似ていますが、 次のような違いがあります。 全体に、その意味を重視して簡明にした感じでしょうか。
抽象クラスは次のように何度も継承できますが、 インターフェイスは一度しか継承できません。
abstract class ClassA {
abstract function methodA();
}

//抽象クラスを継承
class ClassB extends ClassA {
function methodA() { print("A"); }
}

//さらに継承
class ClassC extends ClassB {
function methodB() { print("B"); }
}

var c : ClassC = new ClassC();
c.methodA(); //A
c.methodB(); //B

抽象クラスは多重継承できませんが、インターフェイスは可能です。
interface IntA {
function methodA();
}

interface IntB {
function methodB();
}

//2つのインターフェイスを継承
class ClassA implements IntA, IntB {
function methodA() { print("A"); }
function methodB() { print("B"); }
}

var a : ClassA = new ClassA();
a.methodA(); //A
a.methodB(); //B

あと、抽象クラスは実装を含むことができますが、 インターフェイスは実装が一切あってはいけません。