簡單來說,
宣告在class中,函數外的變量可以被class中所有函數所使用。
舉個例子吧
static int a = 10;
int b=12;
public void MyTest2(int d)//非靜態方法
{
int sum = a + b + d;
Console.WriteLine(sum);
}
public static void MyTest(int a)//靜態方法
{
a = a + 1;
int x = Program.a;
Console.WriteLine(a);
Console.WriteLine(x);
}
static void Main(string[] args)
{
int c = 16;
int d = 33;
MyTest(c);
Program callNonStatic = new Program();
callNonStatic.MyTest2(d);
Console.ReadKey();
}
Main中呼叫MyTest的方法以參數c傳入被 int a接收,因為一開始就宣告了static int a,
若要使用全局變量要以Program.a的方式;而用同樣方式呼叫MyTest2會出現錯誤「需要有物件參考才能使用非靜態欄位、方法或屬性」。這是說明要使用非靜態方法要用該物件來呼叫。
如同紅色的代碼使用方式。
2012年10月16日 星期二
2012年6月20日 星期三
編譯gcc可能遇到的一些error
首先編譯前看看一下我原先配置
$gcc -v
使用內建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6/lto-wrapper
目的:i686-linux-gnu
配置為:../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
執行緒模型:posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
我所要編譯gcc的平台是ubuntu 12.04 32 bit
編譯gcc前請先檢查本身是否已經裝上gcc和binutils否則無法從gcc原碼編譯
還有編譯前要依序安裝gmp > mpfr> mpc
裝gmp前先
$sudo aptitude install build-essential m4
避免錯誤
checking for suitable m4… configure: error: No usable m4 in $PATH or /usr/5bin (see config.log for reasons).
對這三個安裝的配置分別
./configure --prefix=/usr/local/gmp --build=i386-linux-gnu
./configure --prefix=/usr/local/mpfr --build=i386-linux-gnu
./configure --prefix=/usr/local/mpc --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr --build=i386-linux-gnu
可以先創建一個build資料夾讓編譯完的資料可以放在裡面如($表示終端機#表示說明)
$mkdir build
$cd build #跳到此目錄
$../configure --prefix=/usr/gcc-4.7.1 --with-gmp=/usr/local/gmp --with-mpfr=/usr/local/mpfr --build=i386-linux-gnu #--prefix為安裝的路經資料夾
我是裝到/usr/gcc-4.7.1
$make
$make install
三個都安裝完後接著配置
$export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/gcc-4.7.1/lib #gmp, mpfr, mpc都裝到/usr/gcc-4.7.1/了所以這行有沒有沒差(我自己是沒寫這行有錯請跟我說!)
$export LIBRARY_PATH=/usr/lib/i386-linux-gnu
$export C_INCLUDE_PATH=/usr/include/i386-linux-gnu
$export CPLUS_INCLUDE_PATH=/usr/include/i386-linux-gnu
準備開始編譯gcc了
$mkdir build #在源文件下創建build文件
$cd build
$../configure --build=i386-linux-gnu --target=i386-linux-gnu --prefix=/usr/gcc-4.7.1 --with-gmp=/usr/gcc-4.7.1 --with-mpfr=/usr/gcc-4.7.1 --with-mpc=/usr/gcc-4.7.1 --enable-threads=posix --enable-checking=release --enable--long-long --enable-languages=c,c++,java,objc,obj-c++,fortran --enable-shared --with-system-zlib --enable-__cxa_atexit --enable-clocale=gnu --disable-libunwind-exceptions --enable-libgcj-multifile --enable-java-awt=gtk --disable-dssi --enable-plugin --disable-multilib --with-arch=i686
#這邊是我的配置參數粗體部份不可少接著編譯
以下是我遇到的一些error狀況
1)找不到zlib.h文件或zlib.h:No such file or directory
解決$sudo apt-get install zlib1g-dev
2)error: bits/predefs.h:No such file or directory compilation terminated. ,需要安裝包multilib,
解決$sudo apt-get install gcc-multilib
3)缺少gnu/stubs-32.h:No such file or directory, 需要安裝g++-multilib
http://stackoverflow.com/questions/7412548/gnu-stubs-32-h-no-such-file-or-directory
這邊網路上大多是說sudo apt-get install libc6-dev-i386可以解決可是在ubuntu下找不到此安裝套件
也進行$sudo apt-get install g++-multilib, 編譯還是出錯,找不到答案所以參考網友作法用複製的
解決$cp stubs-32.h /usr/include/i386-linux-gnu/gnu /usr/include/gnu
4)error:libxtst file not found
解決sudo apt-get install libxtst-dev
5)error:Package gtk+-2.0 was not found in the pkg-config search path.
解決sudo aptitude install libgtk2.0-dev
6)編譯出現undefined reference to `__sync_bool_compare_and_swap_4'
你在配置./configure 沒加上--with-arch=i686
因為Glibc不再支援i386
編譯完成安裝後
進行舊編譯器保留與應用新的編譯器
$mv gcc gcc463
$mv g++ g++463
$mv cpp cpp463
$mv c++ c++463
連結到新的編譯器
$ln -s /usr/gcc-4.7.1/bin/gcc /usr/bin/gcc
$ln -s /usr/gcc-4.7.1/bin/g++ /usr/bin/g++
$ln -s /usr/gcc-4.7.1/bin/cpp /usr/bin/cpp
$ln -s /usr/gcc-4.7.1/bin/c++ /usr/bin/c++
最後查看一下目前版本
$gcc -v
使用內建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/gcc-4.7.1/libexec/gcc/i386-linux-gnu/4.7.1/lto-wrapper
目的:i386-linux-gnu
配置為:../configure --build=i386-linux-gnu --target=i386-linux-gnu --prefix=/usr/gcc-4.7.1 --with-gmp=/usr/gcc-4.7.1 --with-mpfr=/usr/gcc-4.7.1 --with-mpc=/usr/gcc-4.7.1 --enable-threads=posix --enable-checking=release --enable--long-long --enable-languages=c,c++,java,objc,obj-c++,fortran --enable-shared --with-system-zlib --enable-__cxa_atexit --enable-clocale=gnu --disable-libunwind-exceptions --enable-libgcj-multifile --enable-java-awt=gtk --disable-dssi --enable-plugin --disable-multilib --with-arch=i686
執行緒模型:posix
gcc version 4.7.1 (GCC)
別忘了編譯幾個程式測試這樣完成GCC安裝了!
如果找不到 crt1.o, etc. 可能需要以下處理
ln -s /usr/lib/i386-linux-gnu/crt1.o /lib/crt1.o
ln -s /usr/lib/i386-linux-gnu/crti.o /lib/crti.o
ln -s /usr/lib/i386-linux-gnu/crtn.o /lib/crtn.o
2012年5月29日 星期二
Sql Insert使用ExecuteScalar 方法 避免資料重複
做會員總數或註冊流水號的查詢
在ADO.NET中可以使用ExecuteScalar函數
來查出資料庫中剛註冊會員的流水號(假設名稱是IdNumber),將他設置成主鍵
並且自動增號
在我插入新增資料後接著ExecuteNonQuery再做ExecuteScalar
資料發生重複(插入)輸入的情況。當然重複的資料鍵值不同ExecuteScalar所找到的是第二次重複資料的流水號。目前還沒找到為甚麼會複製的資料。可能是自動增號的關係?
解決方法
1)
ExecuteNonQuery
select @@identity
ExecuteScalar
2)
Insert into tablename output inserted.IdNumber ....
ExecuteScalar
以上非完整code
就不會有重複資料了
參考閱讀(簡體)
http://www.bitscn.com/pdb/dotnet/200807/145550.html
http://www.w17x.com/AritcleDisplay.aspx?id=519
2012年5月23日 星期三
ADO dot NET 連結 VC內建MDF
用Visual Studio 來寫SQL,偵錯時一直沒成功,後來發現是我的Instance名稱不對
下面是很多前輩實行成功的code ! 別忘了用using來進行資源釋放
string dataDir = AppDomain.CurrentDomain.BaseDirectory;
if (dataDir.EndsWith(@"\bin\Debug\")
|| dataDir.EndsWith(@"\bin\Release\"))
{
dataDir = System.IO.Directory.GetParent(dataDir).Parent.Parent.FullName;
AppDomain.CurrentDomain.SetData("DataDirectory", dataDir);
}
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
備註:紅色是Instance名 ;藍色是資料表名稱
2012年5月11日 星期五
有些網站會要求存取您的「Google 帳戶」,您無意間授權多少網站呢??
如同頁面所說
Google 允許您與第三方網站分享您的 Google 帳戶資訊,而不會洩漏您的使用者名稱和密碼。
您可以透過「Google 帳戶」與另一網站分享的資訊有:
- 電子郵件地址
- 姓名
- 國家/地區和語言
- 瀏覽您的 Google 產品資訊,例如您的 Gmail 聯絡人、Google 日曆或 Picasa 網路相簿。
2012年5月7日 星期一
修改登錄值強化SSD加速Windows 7效能幾個小步驟
網上有很多說明與解釋的部分了,如果想知道原因請自行搜索
這邊蒐集網上一些資料也是我自己用到的設定,並快速說明
順便筆記一下也提供網友參考,但是修改登錄值都有一定的風險
請自行斟酌是否進行設定
說明一下我的平台是Win x64配上SSD
3. ReadyBoot
控制台>系統管理工具>資料搜集器集合工具 --> 啟動事件追蹤工具階段 --> ReadyBoot
"追蹤工具階段" :停用
4.TimeStampInterval
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Reliability
TimeStampInterval預設值 1 改為 0
5.PagingExecutive
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management
DisablePagingExecutive 預設值 0 改為 1
6.執行msconfig>開機:最大核心與最大記憶體開機、無GUI開機(跳過四球組成windows圖案畫面)
7.Windows Customer Experience Improvement Program(CEIP)
a.停用CEIP
執行 gpedit.msc 本機原則有電腦和使用者設定:
系統管理範本 -> 系統 -> 網際網絡通訊管理 -> 網際網絡通訊設定 "關閉 Windows 客戶經驗改進計劃" 右鍵編輯選項內 "已啟用"
b.執行 taskschd.msc 工作排程器程式庫 -> Microsoft -> Windows -> Customer Experience Improvement Program 左鍵停用全部排程
c.執行 taskschd.msc 工作排程器程式庫 -> Microsoft -> Windows -> RAC 左鍵停用全部排程
8.停止 Superfetch 服務:
執行 services.msc , 找到Superfetch 服務 將"手動" 改為 "停止",亦會同值停止了 Prefetch 及 ReadyBoost
9.SSD停用磁碟重組排程
10.轉移暫存檔案
系統內容>進階>環境變數
11.分頁檔轉移至別槽可延長SSD壽命(可能降低OS效能)**
系統內容>進階> 效能設定>進階>虛擬記憶體
12.其他關閉IPv6、停用休眠,以及轉移使用者設定可自行前往參考
這邊蒐集網上一些資料也是我自己用到的設定,並快速說明
順便筆記一下也提供網友參考,但是修改登錄值都有一定的風險
請自行斟酌是否進行設定
說明一下我的平台是Win x64配上SSD
- AHCI: 執行 regedit
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Msahci
start預設值改為0
在進BIOS開啟 AHCI - 開啟trim: 執行 CMD
鍵入fsutil behavior set disabledeletenotify 0
檢查是否有無開啟小工具 DriveControllerInfo ,顯示Enable即是
或fsutil behavior query disabledeletenotify (1是關閉0為開啟)
3. ReadyBoot
控制台>系統管理工具>資料搜集器集合工具 --> 啟動事件追蹤工具階段 --> ReadyBoot
"追蹤工具階段" :停用
4.TimeStampInterval
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Reliability
TimeStampInterval預設值 1 改為 0
5.PagingExecutive
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management
DisablePagingExecutive 預設值 0 改為 1
6.執行msconfig>開機:最大核心與最大記憶體開機、無GUI開機(跳過四球組成windows圖案畫面)
7.Windows Customer Experience Improvement Program(CEIP)
a.停用CEIP
執行 gpedit.msc 本機原則有電腦和使用者設定:
系統管理範本 -> 系統 -> 網際網絡通訊管理 -> 網際網絡通訊設定 "關閉 Windows 客戶經驗改進計劃" 右鍵編輯選項內 "已啟用"
b.執行 taskschd.msc 工作排程器程式庫 -> Microsoft -> Windows -> Customer Experience Improvement Program 左鍵停用全部排程
c.執行 taskschd.msc 工作排程器程式庫 -> Microsoft -> Windows -> RAC 左鍵停用全部排程
8.停止 Superfetch 服務:
執行 services.msc , 找到Superfetch 服務 將"手動" 改為 "停止",亦會同值停止了 Prefetch 及 ReadyBoost
9.SSD停用磁碟重組排程
10.轉移暫存檔案
系統內容>進階>環境變數
11.分頁檔轉移至別槽可延長SSD壽命(可能降低OS效能)**
系統內容>進階> 效能設定>進階>虛擬記憶體
12.其他關閉IPv6、停用休眠,以及轉移使用者設定可自行前往參考
2012年5月3日 星期四
Norton ConnectSafe (norton dns)遠離不安全和令人討厭的網站
Norton ConnectSafe (norton dns)遠離不安全和令人討厭的網站,不用安裝額外的軟體。
並在站在第一線幫你封鎖不安全的網站內容,Norton ConnectSafe並不能完全取代您電腦的網路安全套裝軟體(如卡巴斯基/EAST NOD),但能在瀏覽網頁時提供安全並過濾不信任的網站內容。
官方網頁:https://dns.norton.com/dnsweb/homePage.do
說明:有家庭用戶(完全免費)和商業用戶之分
如何開始使用?
STEP1
STEP2:如果家裡沒有路由器就選第二個選項,選擇第一個是在使用路由器的情況下能一次幫你網路中的電腦使用NORTON DNS防護
STEP2:接著會看到有三種方案
A過濾掉含有惡意軟體,網路釣魚的網站
B過濾掉色情內容的網站在加上A的方案
C提供過濾一些包含暴力/自殺/墮胎/藥物濫用/賭博性的網站對於家中有小孩是不錯選擇方案並在加上A/B的過濾內容
STEP3:怎麼使用?(以windows 7為例)
1開啟網路共用中心
2檢視作用中的網路
3選擇區域連線->內容->選擇網際網路通訊協定第四版(TCP/IPv4) ->內容
在DNS部分輸入步驟二方案提供的IP位址
STEP4:怎麼看有沒有啟用?
1重新連線
如果出現
"Your computer is currently using Norton DNS."
便是設定成功STEP5:Norton DNS速度會不會很慢?
用DNS Benchmark來看跟Google Public DNS不相上下
2012年3月30日 星期五
Vidalia Bundle Portable 免安裝
官方網頁:https://www.torproject.org/index.html.en
軟體名稱:Vidalia Bundle portable
軟體版本:Polipo Tor 0.2.2.35 Vidalia 0.2.17
軟體說明:
Vidalia lets you start and stop Tor, see how much bandwidth you are consuming, see how many circuits you currently have active, see where these circuits are connected on a global map, view messages from Tor about its progress and current state, and let you configure your Tor client, bridge, or relay with a simple interface. Included in Vidalia is an extensive help system which helps you understand all of the options available to you. All of these features are translated into a large number of languages.
以上取自官方說明
軟體大小:15.2 MB
軟體截圖:
附註說明:請選擇 Vidalia 執行程式
下載連結:Vidalia Bundle ( Windows 7, Vista, and XP )
2012年3月28日 星期三
BurnInTest V7.0 Standard portable免安裝
官方網頁:http://www.passmark.com/
軟體名稱:BurnInTest Standard edition (標準版)
軟體版本:7.0 b1009
軟體說明:
PassMark BurnInTest™ is a software tool that allows all the major sub-systems of a computer to be simultaneously stress tested for endurance, reliability and stability.
- Assists in PC Troubleshooting and diagnostics.
- The best value professional burn-in tool on the market!
- The hottest, fastest CPU Burn In tool around! (See our CPU Heat Generation benchmark testing)
- Avoid delivering D.O.A. (Dead on Arrival) hardware to your customers.
- Dramatically reduce your burn in times with multithreaded simultaneous testing of components.
- Build your image as a supplier of quality systems.
- Avoid costly downtime, system rebuilds and lost data.
- Test the stability of a system after configuration changes or hardware upgrades (critical for overclocking).
軟體大小:7.80 MB
軟體截圖:
附註說明:
此版為32bit 版本,已於經Windows 7 x64測試,本軟體不帶任何註冊訊息。
比較版本:官方說明
下載連結:Download BurnInTest Standard edition V7.0 (32-bit)
標籤:
燒機,
BurnInTest
訂閱:
文章 (Atom)