C#從零開始_自學C#、Visual Studio實境秀 31/ ToolTip Static Constructors 字串比對與尋找 using alias namespace 括號{



31/ ToolTip Static Constructors 字串比對與尋找 using alias namespace 括號{ https://youtu.be/EZFSm1ceG4g

部件篩選器 原來在 ToolTip 在 Form2 建構,加入事件處理程序是錯誤的!

19:00 C# Special Characters (@、$) http://bit.ly/2t7J4ep

27:00 @ (C# Reference) http://bit.ly/2v6g87I

29:00 $ (C# Reference) http://bit.ly/2unHBV3 以上二者一定要緊接著後面的字元

48:30 scope 翻成「結界」也很適當傳神!

51:40 . Operator (C# Reference) http://bit.ly/2t4s9ZY

59:00 方括號(中括號、中括弧、方括弧)Square brackets ([]) are used for arrays, indexers, and attributes.  http://bit.ly/2uxl2xQ

1:09:00 () Operator (C# Reference) parentheses 圓括弧 圓括號 小括號 小括弧

1:12:00 Casting and Type Conversions.

Methods (C# Programming Guide)

1:15:00 Method Signatures http://bit.ly/2t4cMkn

1:20:00 Method Parameters vs. Arguments 原來 Parameters 和 Arguments 是不一樣的東西! http://bit.ly/2t4cMkn

1:24:40 :: Operator (C# Reference) http://bit.ly/2vr1YNY 1:31:20 In general, use :: to reference a namespace alias or global:: to reference the global namespace and . to qualify types or members. 1:34:20 原來兩個冒號是這樣用:
using Als = System;

 class TestClass

 {

  static void Main()

  {

   // Error

   //Alias::WriteLine("Hi");



   // OK

   Als::Console.WriteLine("Hi");

   Als.Console.WriteLine("Hi");//二式相等。但是還是以上式為無後顧之憂:Using :: with aliases is a good idea and protects against the unexpected introduction of additional types.    

   Als.Console.Read();

  }

 } //http://bit.ly/2tYvviL

1:46:00 How to: Use the Global Namespace Alias (C# Programming Guide)  http://bit.ly/2tYxbsx

1:26:00 Fully Qualified Names 完整名稱 http://bit.ly/2tYvviL

Using the previous code segment, you can add a new class member, C3, to the namespace N1.N2 as follows:
 namespace N1.N2

 {

  class C3   // N1.N2.C3

  {

  }

 }

2:15:10 Static Constructors (C# Programming Guide) http://bit.ly/2sXUWhZ

2:19:00 DateTime.Now.Ticks

2:25:00 Static constructors are also useful when creating wrapper classes for unmanaged code,

2:29:00 所以 constructors 有幾種:Instance Constructors (C# Programming Guide) Static Constructors :

The sample output verifies that the static constructor runs only one time, even though two instances of Bus are created, and that it runs before the instance constructor runs.

// Static constructor is called at most one time, before any

    // instance constructor is invoked or member is accessed.

2:34:00 試作一個主控台應用程式將網址中的「zh-tw」改成「en-us」;反之亦然。 3:45:00 3:47:40 隱藏主控台應用程式的 Console 小黑窗

using System;
using System.Windows;
using followHTTPsysDiag = System.Diagnostics;// using alias 
//利用C#隱藏Console Window命令模式視窗 http://bit.ly/2tZWfzj
namespace docs_microsoft_page_ConsoleApp//把線上技術手冊網址中英互換
{
    class Program
    {
        [STAThread]//http://bit.ly/2v8oaxg
        static void Main(string[] args)
        {
            String add = String.Empty;
            add=Clipboard.GetText();//先複製原網址到剪貼簿以供讀取
            if (add.IndexOf("https://docs.microsoft.com/") == -1) return;//http://bit.ly/2upzXtn
            if (add.IndexOf("zh-tw") > 0) add=add.Replace("zh-tw", "en-us");
            else if (add.IndexOf("en-us") > 0) add=add.Replace("en-us", "zh-tw");
            followHTTPsysDiag::Process.Start(add);//http://bit.ly/2vsxZp4 另可參:http://bit.ly/2tZkcZg http://bit.ly/2vsii1d
            /*
            using System;
            using System.Windows.Forms;
 
            namespace WindowsFormsApplication1
            {
                public partial class Form1 : Form
                {
                    public Form1()
                    {
                        InitializeComponent();
                    }
 
                    private void button1_Click(object sender, EventArgs e)
                    {
                        //使用預設瀏覽器
                        System.Diagnostics.Process.Start( "http://google.com.tw");
 
                        //使用IE瀏覽器
                        System.Diagnostics.Process.Start("iexplore.exe", "http://google.com.tw");
 
                        //使用Chrome瀏覽器
                        System.Diagnostics.Process.Start("chrome.exe", "http://google.com.tw");
 
                        //使用Firefox瀏覽器
                        System.Diagnostics.Process.Start("firefox.exe", "http://google.com.tw");
 
                        //使用Safari瀏覽器
                        System.Diagnostics.Process.Start("safari.exe", "http://google.com.tw");
                    }
                }
            }
            */
        }
    }
}
2:53:00 練習用 using alias 寫 和 :: 引用其成員

3:07:00 ControlCollection.IndexOf Method 可用在五子棋棋子的判斷上。 http://bit.ly/2upCSlZ

3:10:20 尋找字串,或比對字串 http://bit.ly/2upzXtn String.IndexOf Method

How to: Search Strings Using String Methods (C# Programming Guide) http://bit.ly/2uz2X2m

3:26:00 3:28:55 using 陳述式 (C# 參考)  a curly braces(大括弧 大括號)

4:02:00 Static Constructors Example  Instance constructor.

4:09:00 「靜態建構函式並不使用存取修飾詞,也沒有參數。」所以一定是 private

4:13:30 試作一個讀取剪貼簿資料以開啟 google 翻譯的 Console app

using System;
using STRExp=System.Text.RegularExpressions;
using static   System.Windows.Clipboard;
using SD = System.Diagnostics;
using static System.Environment;

namespace google_translation_ConsoleApp
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            string word = GetText();
            if(String.IsNullOrWhiteSpace(word)) return;
            STRExp::Regex reg = new STRExp.Regex("[0-9]");
            if (reg.IsMatch(word)) return;
            const string address = @"https://translate.google.com/?source=gtx#auto/zh-TW/";
            //判斷是否有換行 http://bit.ly/2uu2Y6V  http://bit.ly/2twgwue
            if (word.IndexOf(NewLine)>-1) word=word.Replace(NewLine, " ").Replace("  "," ").Replace(@"/","");
            while (word.IndexOf("  ")>-1) word=word.Replace("  ", " ");
            SD::Process.Start(address+ word.Trim());
        }
    }
}
4:44:10 自訂工具列圖示文字一起顯示

5:00:00 5:05:00 取代換行字元及指定字元「@"/"」等。

5:24:00 5:25:50 讓程式執行暫停:

        // Wait for bus2 to warm up.

        System.Threading.Thread.Sleep(10000);//暫停十秒

5:28:00 Instance Constructors (C# Programming Guide) http://bit.ly/2vsupuQ

5:39:00 To initialize a static class, or static variables in a non-static class, you must define a static constructor. For more information, see Static Constructors.

5:45:00 A constructor like this one, which takes no arguments, is called a default constructor. 預設的建構子其實就是沒有參數的建構子。

5:29:20 new (C# Reference) http://bit.ly/2upOWDJ 5:36:00 new (C# 參考)

5:48:30 Default Values Table (C# Reference) http://bit.ly/2tvUSq4

{

6:00:00 Remember that using uninitialized variables in C# is not allowed. 還未初始化的都是 null;

}

5:57:00 ?? Operator (C# Reference) http://bit.ly/2vsV8Yu 6:28:40 試作 ??  有點像 Nz() or IsNull() 或之前學的 IsNullOrEmpty 之類。如 person.name?? "Is Null!" 若左邊是 Null,則傳回右邊,若左邊不是 Null,則傳左邊值

6:25:00 Reference Types (C# Reference) http://bit.ly/2v83jtV http://bit.ly/2upRh1i Value Types Table (C# Reference)

6:55:25 Constructors (C# Programming Guide) http://bit.ly/2uq6jUN

{6:58:44 http://bit.ly/2uqjZix Using Constructors (C# Programming Guide) Unless the class is static, classes without constructors are given a public default constructor by the C# compiler in order to enable class instantiation.

靜態的欄位只能用靜態的建構子來初始化:If your class contains static fields, provide a static constructor that initializes them when the class is loaded. http://bit.ly/2sQC7Co

stati class 的生命期也是類似 VB 中的 static :a static class remains in memory for the lifetime of the application domain in which your program resides.

Static classes are sealed and therefore cannot be inherited. They cannot inherit from any class except Object. Static classes cannot contain an instance constructor; however, they can contain a static constructor. Non-static classes should also define a static constructor if the class contains static members that require non-trivial initialization. For more information, see Static Constructors.

}

}


留言

熱門文章