乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      C Sharp與.net學習筆記(一)

       kittywei 2012-01-31
      • C#和.net都是零基礎(chǔ),需要一到兩周先惡補一點東西,特此記錄一下 2012.01.11

      C#控制臺程序

      一個入門用的hello world程序如下:

      using System;
      
      class CSharpTest
      {
          static void Main()
          {
              Console.WriteLine("Hello world not using Qt");
          }
      }

      編譯

      E:\Test1> csc hello.cs

      運行

      E:\Test1> hello
      Hello world not using Qt

      有沒有問題?

      • 返回值何在?
      • 命令行參數(shù)如何獲???
      • 入口點必須為Main?如果多個類的話,怎么找到入口的
      • ...

      入口點

      可用的入口點(需要時某個類的靜態(tài)成員函數(shù),MSDN中 Hello World in Visual C#中提到必須是public,但似乎private也沒有問題):

      • static void Main()

      • static int Main()

      • static void Main(string[] args)

      • static int Main(string[] args)

      如果下面這樣的程序,還能直接csc hello.cs編譯么?

      using System;
      
      class CSharpTest
      {
          static void Main()
          {
              Console.WriteLine("Hello world not using Qt");
          }
      }
      
      class CSharpTest2
      {
          static void Main(string [] args)
          {
              Console.WriteLine("Hello world not using Qt too");
          }
      }

      如何解決?可以用

      csc /main:CSharpTest  hello.cs

      csc /main:CSharpTest2  hello.cs

      選擇入口點。

      如果一個類內(nèi)多個入口點函數(shù),似乎就沒辦法了(fixme)

      返回值

      • 返回值是 int 的入口點,然后直接使用return即可

      using System;
      
      class CSharpTest
      {
          static int Main()
          {
              Console.WriteLine("Hello world not using Qt");
              return 1;
          }
      }

      結(jié)果

      E:\Test1>hello
      Hello world not using Qt
      
      E:\Test1>echo %errorlevel%
      1

      可以直接使用 System.Environment.Exit

      using System;
      
      class CSharpTest
      {
          static void Main()
          {
              Console.WriteLine("Hello world not using Qt");
              Environment.Exit(1);
          }
      }

      而不用考慮入口點函數(shù)是否返回值是int

      命令行參數(shù)

      似乎沒什么好說的,與C++的不同處在于,參數(shù)中第一個不是程序名

      using System;
      
      class CSharpTest
      {
          static void Main(string[] args)
          {
              foreach (string arg in args)
                  Console.WriteLine(arg);
          }
      }

      結(jié)果:

      E:\Test1>hello Qt5 Qt4 Qt3
      Qt5
      Qt4
      Qt3

      Gui程序(Windows Forms)

      使用Windows Forms:

      using System.Windows.Forms;
      
      class CSharpTest
      {
          static void Main()
          {
              MessageBox.Show("Hello World not using Qt");
          }
      }

      是這么編譯么?

      csc hello.cs

      恩,可以,只不過有cmd窗口彈出。需要指定

      csc /arget:winexe hello.cs

      一般情況下,會需要使用一個Application(用來控制程序的啟動、停止、消息處理等)

      using System.Windows.Forms;
      
      public class Form1 : Form
      {
          public static void Main()
          {
              Application.Run(new Form1());
          }
      
          public Form1()
          {
              this.DoubleClick += new System.EventHandler(form_Click);
          }
      
          private void form_Click(object sender, System.EventArgs e)
          {
              Application.Exit();
          }
      }

      編譯命令同上

      Gui程序(WPF)

      這應(yīng)該是最簡單的WPF的程序了吧?

      using System.Windows;
      
      public class WpfTest1
      {
          public static void Main()
          {
              MessageBox.Show("WPF Applicaiton Test");
          }
      }

      編譯(好像必須指定這些reference,fixme):

      E:\Test1>csc /target:winexe /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\W
      indowsBase.dll"  hello.cs

      正常情況下,我們需要有Application(和Windows.Forms中的不是同一個)

      using System.Windows;
      
      public class WpfTest1
      {
          public static void Main()
          {
              Application app = new Application();
              app.Run();
          }
      }

      編譯命令同上

      而一旦有了xaml,似乎只靠命令行工具就很難搞定了。需要有csproj這樣的工程文件,然后用msbuild或者直接使用visual studio了。好麻煩...(xaml被編譯成了baml資源,然后嵌入到最終的dll或exe中)

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多