發表文章

目前顯示的是 5月, 2017的文章

C#

C#  [**] static 方法 只能存取外部的static 變數 //Example.cs namespace TetrisServer {     class Program     {         static private string ip;         private int port;         static void Main(string[] args)         {             ip = "XXX"; //OK             port = 57; // fail         }     } } 字串處理 1. string str = "asdaa asd qwe"; string str1 = str.Substring(0,str.IndexOf(" ")); //=> "asdaa" string str2 = str.Substring(str.IndexOf(" ")+1); //=> "asd" 2. string str = "asdqwe asd sad"; string[] strr = str.Split(new char[] { ' ' }); //=> strr = "asdqwe","asd","sad" ----------------------------------------------------------------------------------------------------------------------- string 加入換行 string str = str + System.Environment.NewLine; --------------------------------------------------------------------------------------------------------

C# Program 常見錯誤

沒有實體 1.new 物件陣列 ,每個element還是 null 2. new 物件,每個member還是null public class subClass { public int i; }; public class myclass {public int i; public subClass s;} public class Program{           static public T [] CreateInitializedArray < T >( int size ) where T : new () { var arr = new T [ size ]; for ( int i = 0 ; i < size ; i ++) arr [ i ] = new T (); return arr ; }         static void Main()         {            myclass[] c = new myclass[5];             //錯誤1             c[0].i = 5;// c[0] is null !!               //修正1.1            for(int i=0; i<5; ++i)                c[i] = new myclass();              // 修正  1.2             c = CreateInitializedArray<myclass>(5);             //---------------------------------------------------             c[0].s.i = 4;  //錯誤2 : c[0].s is null               // 修正  2               c[0].s = new subClass();              c[0

C# DataStructure2

class 成員 的 get set class Pet { public string Name { get ; set ; } public int Age { get ; set ; } } public static void Ex1() { Pet[] pets = { new Pet { Name= "Barley" , Age=8 }, new Pet { Name= "Boots" , Age=4 }, new Pet { Name= "Whiskers" , Age=1 } }; } Array 長度 int[] a = new int[5]; int l = a.Length; => l=5

C# DataStructure

1.List<T>.OrderBy() 用法 ---------------------------------------------------- 原型: public static IOrderedEnumerable<TSource> OrderBy<TSource, TKey>( this IEnumerable<TSource> source, //不用理他 Func<TSource, TKey> keySelector //! ) ---------------------------------------------------- class Pet { public string Name { get ; set ; } public int Age { get ; set ; } } public static void OrderByEx1() { Pet[] pets = { new Pet { Name= "Barley" , Age=8 }, new Pet { Name= "Boots" , Age=4 }, new Pet { Name= "Whiskers" , Age=1 } }; IEnumerable<Pet> query = pets.OrderBy(pet => pet.Age); //指定 keyseletor foreach (Pet pet in query) { Console.WriteLine( "{0} - {1}" , pet.Name, pet.Age); } } ========================================================================================= http://ithelp.ithome.com.tw/articles/10100451 2

C# 各類控制項

圖片
1. DataGridView 可以一行一行加入。 DataGridViewDisableButtonCell buttonCell = (DataGridViewDisableButtonCell)dataGridView1.Rows[index].Cells[2]; 2. TextBox Note    The  ReadOnly  property only affects user interaction at run time. You can still change text box contents programmatically at run time by changing the  Text  property of the text box. 3 .PictrueBox 動態載入圖片:1.點選 右方 property 會出現 一個視窗 2.進入視窗的"資源"頁並加入 picture   3.在程式裡打入  pictureBox1.Image = Properties.Resources.Icon;

TEST

圖片
測試asldhaskljdhkljashdlkjahsdkjlashdkj https://www.youtube.com/watch?v=r18tmg0E_5A