TcpClient.Connected 屬性
取得值,指出 TcpClient 的基礎 Socket 是否已連接至遠端主機。
createps 發表在 痞客邦 留言(0) 人氣(2,685)
在虛擬交易峰會倫敦站上,GameDuell聯合創始人Michael
Kalkowski向開發者和用戶剖析了facebook排名前25款社交遊戲共有的一些基本元素,而這些可以用以協助其他的開發者提高他們在社交遊戲領域的虛擬成交額度。
畢竟虛擬交易所創造的收益是社交遊戲目前營收的主要途徑,據Michael
Kalkowski分析現在整體遊戲的虛擬營收總值將高達750億美元。
createps 發表在 痞客邦 留言(0) 人氣(1,145)
inline 這個關鍵字是使用在function前面
inline 所宣告的function並不會有程式本體
而是像巨集(define)一樣 會直接展開到呼叫他的地方
inline的優點
在類別(class)中 我們常需要使用一個function將一個變數傳出去 比方說
int CMyClass::GetValue()
{
return m_nValue;
}
我們知道 function的呼叫 是非常花CPU時間的 而function裡面卻只有傳回一個數值而已
這樣的動作 對於CPU的使用非常沒有效率
當然 我們可以將這個變數改成public 讓其他人直接來存取
不過這是一個不好的寫法
比較好的寫法是使用inline function 來解決這個問題
經過inline所宣告的function會直接展開在程式碼內
所編出來程式碼就會直接去存取那個參數 省略了呼叫function的時間浪費
inline與#define的比較
inline 其實就是將一個function直接展開到程式碼內
這樣的功能 透過巨集也可以達到 不過巨集跟inline還是有些差異的
1. 巨集當然不可能將public以外的變數傳出去 inline可以
2. 巨集跟inline有時候結果會不同 如下所示
#define D_TRIPLE(n) (n+n+n)
int GetValue();
inline int I_TRIPLE(int n)
{
return n+n+n;
}
void main()
{
int a = 1;
int b = 1;
int r1 = D_TRIPLE(GetValue());
int r2 = I_TRIPLE(GetValue());
}
r1是使用巨集 他會將GetValue()展開到程式碼中三次 如此r1是將三次呼叫GetValue()的值相加
r2是使用inline function他只會呼叫GetValue()一次 之後便將這個值相加起來(三個相加)
inline的使用
inline的使用非常簡單 只需要在function宣告前加上inline即可(如前面範例所示)
另外 如果將function的內容直接寫在類別(class)宣告中的話 編譯器會直接把他當做inline
例如
class CMyClass
{
int m_nValue;
int GetValue()
{
return m_nValue;
};
}
以上的GetValue()並沒有宣告成inline 但是編譯器還是會直接將他當作inline function
inline的使用效益問題
最後 一個function是否要用inline來展開的決定權 還是在編譯器手上
編譯器會自己評估 將這個function用inline來展開合不合效益
如果說程式碼很長 使用inline並不能節省多少CPU時間 然後卻又被呼叫很多次
編譯器會判斷不合效益 則會自動忽略掉inline
createps 發表在 痞客邦 留言(1) 人氣(12,232)
*.lib 和 *.dll 有什麼區別?
首先,Lib文件不是可執行文件,裡面沒有可執行部分。你知道DLL吧,實際上DLL是個二進制文件,裡面有可執行代碼、資源等等。但是我們的調用程序如何知道從哪裡開始執行該二進制文件哩?這時候必須給定一個接口,告訴調用DLL文件的程序在調用的時候從哪裡開始進入,或者說DLL中導出的函數入口有哪些。這時候才引入了Lib文件,因此Lib文件實際上是DLL導出函數的定義。
createps 發表在 痞客邦 留言(0) 人氣(1,014)
string[] 版號 = Application.ProductVersion.Split('.');
string 版本 = 版號[0] + "." + 版號[1] + "." + 版號[2];
createps 發表在 痞客邦 留言(0) 人氣(415)
You have a TextBox control on your Windows Forms application and need to detect Enter. The TextBox allows your users to type letters into it, and you need to detect when a certain key is pressed. Our solution involves the KeyDown event in our C# Windows Form. We use the KeyDown event for our code.
Using KeyDown event
Open designer and click on TextBox. In the Visual Studio 2008 designer, click on your TextBox control in the form display. You will see the Properties Pane. Next, click on the lightning bolt icon. This icon stands for events. In the event tab, scroll to KeyDown, and double click in the space to the right. New code like that highlighted below will appear.
createps 發表在 痞客邦 留言(0) 人氣(600)
C#:
前面補0的數字字串
String.Format("{0:0000}", 157); // 輸出 0157
前後都補0的數字字串
String.Format("{0:0000.0000}", 157.42); // 輸出 0157.4200
每3位數(千)加逗號
(String.Format("{0:0,0}", 38560); // 輸出 38,560
0:0 這樣表示會把前面補0 ,例如本來是6,會顯示06,所以不要有0: 就不會變成06
createps 發表在 痞客邦 留言(0) 人氣(17,635)
同步發表於Google Blogger Dictionary<string, object> tagDictionary = new Dictionary<string, object>();
private void Form1_Load(object sender, EventArgs e)
{
tagDictionary.Add("AnimatedModelData",1000);
}
private void button1_Click(object sender, EventArgs e)
{
if (tagDictionary["AnimatedModelData"] != null)
{
int i = (int)tagDictionary["AnimatedModelData"];
}
}
createps 發表在 痞客邦 留言(0) 人氣(16,198)
//=========================================================================================
不取得子目錄的話用這個:
string[] dirs = Directory.GetDirectories(@"c:\");//路徑
foreach (string dir in dirs)
{
Console.WriteLine(dir);
}
文件的話把GetDirectories改成GetFiles
如果要遞歸的話,就是想取得此目錄下所有子目錄和文件的辦法用這個:
public void FindFile(string dir) //參數為指定的目錄
{
//在指定目錄及子目錄下查找文件,在listBox1中列出子目錄及文件
DirectoryInfo Dir=new DirectoryInfo(dir);
try
{
foreach(DirectoryInfo d in Dir.GetDirectories()) //查找子目錄
{
FindFile(Dir+d.ToString()+"\\");
listBox1.Items.Add(Dir+d.ToString()+"\\"); //listBox1中填加目錄名
}
foreach(FileInfo f in Dir.GetFiles("*.*")) //查找文件
{
listBox1.Items.Add(Dir+f.ToString()); //listBox1中填加文件名
}
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
}
調用
private void button1_Click(object sender, System.EventArgs e)
{
string currentdir="c:\\testfolder"; //搜索的目錄
if(currentdir[currentdir.Length-1]!='\\') //非根目錄
currentdir+="\\";
FindFile(currentdir); //調用查找文件函數
}
注意 using System.IO;
//=========================================================================================
createps 發表在 痞客邦 留言(0) 人氣(1,298)
createps 發表在 痞客邦 留言(0) 人氣(15,018)