カテゴリー
SugiBlog Webデザイナー・プログラマーのためのお役立ちTips

フルパスからファイル名を取得

System.IO.Path.GetFileName("…");
2,054 views

1枚のNICに複数のIPアドレスを設定する

eth0192.168.255.1を追加する例

cd /etc/sysconfig/network-scripts
cp ifcfg-eth0 ifcfg-eth0:0
vi ifcfg-eth0:0
DEVICE=eth0:0
IPADDR=192.168.255.1
NETMASK=255.255.255.0
NETWORK=192.168.255.0
BROADCAST=192.168.255.255
ONBOOT=yes
BOOTPROTO=none
/etc/rc.d/init.d/network restart

ifconfigで確認

1,500 views

コンストラクタ・デストラクタ

コンストラクタ

コンストラクタはconstructor[構築子]といって、クラスのインスタンスが生成されるときに実行されるメソッドです。

デストラクタ

デストラクタはdestructor[消去子]といって、クラスのインスタンスが消去されるときに実行されるメソッドです。

利用例

PHP
class Exam {
    function __construct() {
    }
    function __destruct() {
    }
}
C#
class Exam {
    function Exam() {
    }
    function ~Exam() {
    }
}
Swift

Swiftの場合、イニシャライザ・デイニシャライザ

class Exam {
    init() {
    }
    deinit {
    }
}
1,590 views

xor(排他的論理和)

0x0C=12=1100
0x06=6=0110

1100 ^ 0110 = 1010 = 10 = 0x0A
1100 xor 0110 = 1010 = 10 = 0x0A

1,975 views

デリゲート(delegate)

バックグラウンドで処理を実行中、メインスレッドのメソッドを実行したいとき、
通常のようには呼び出せないので、デリゲートを使って呼び出します。

メインスレッド

Thread tMain = new Thread(new ThreadStart(SampleThread));
tMain.IsBackground = true;
tMain.Start();

デリゲートの定義

delegate void SampleDelegate(string args);

メソッドの定義

private void SampleMethod(string args)
{
    Console.Writeline(args);
}

スレッド

private void StartServer()
{
    this.Invoke(new SampleDelegate(this.SampleMethod), "sample text");
}

続きを読む…»

1,966 views