熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

Visual C# .NET 入門:小結

2022-06-13   來源: .NET編程 

  本入門指南旨在幫助您用 Visual Studio 構建一個簡單的 C# 項目它無法進行全面的介紹我們鼓勵您查詢關於 C# 和 NET 的其他資源以便更多地學習這些技術在完成本教程之後您至少有了一個可用的項目在您研究 Visual C# 時可以從修改此這些代碼開始

  為了方便起見我們提供了完整的源程序和項目文件您可以通過本文檔頂部的目錄來訪問它們

  其他資源我們強烈推薦下面這些關於 C# 和 NET 平台的書籍它們是開發人員嘗試學習這些新技術的有益資源

  Archer TomInside C#RedmondMicrosoft Press

  Deitel HarveyC#How to ProgramUpper Saddle River NJPrentice Hall

  Gunnerson EricA Programmers Introduction to C#New YorkApress

  Platt DavidIntroducing Microsoft NETRedmondMicrosoft Press

  補遺QuickSort C# NET 的源代碼下面是 QuickSort C# NET 示例應用程序的完整源代碼您可以復制使用和分發這些代碼(無版權費)注意這些源代碼以原樣提供並且不作任何保證

  //
//  QuickSort C# NET Sample Application
//  Copyright Microsoft Corporation All rights reserved
//
//  MSDN ACADEMIC ALLIANCE []
//  This sample is part of a vast collection of resources we developed for
//  faculty members in K and higher education Visit the MSDN AA web site for more!
//  The source code is provided as is without warranty
//
// Import namespaces
using System;
using SystemCollections;
using SystemIO;
// Declare namespace
namespace MsdnAA
{
    // Declare application class
    class QuickSortApp
    {
        // Application initialization
        static void Main (string[] szArgs)
        {
            // Print startup banner
            ConsoleWriteLine (\nQuickSort C#NET Sample Application);
            ConsoleWriteLine (Copyright (c) Microsoft Corporation All rights reserved\n);
            ConsoleWriteLine (MSDN ACADEMIC ALLIANCE []\n);
            // Describe program function
            ConsoleWriteLine (This example demonstrates the QuickSort algorithm by reading an input file);
            ConsoleWriteLine (sorting its contents and writing them to a new file\n);
            // Prompt user for filenames
            ConsoleWrite (Source: );
            string szSrcFile = ConsoleReadLine ();
            ConsoleWrite (Output: );
            string szDestFile = ConsoleReadLine ();
            // Read contents of source file
            string szSrcLine;
            ArrayList szContents = new ArrayList ();
            FileStream fsInput = new FileStream (szSrcFile FileModeOpen FileAccessRead);
            StreamReader srInput = new StreamReader (fsInput);
            while ((szSrcLine = srInputReadLine ()) != null)
            {
                // Append to array
                szContentsAdd (szSrcLine);
            }
            srInputClose ();
            fsInputClose ();
            // Pass to QuickSort function
            QuickSort (szContents szContentsCount );
            // Write sorted lines
            FileStream fsOutput = new FileStream (szDestFile FileModeCreate FileAccessWrite);
            StreamWriter srOutput = new StreamWriter (fsOutput);
            for (int nIndex = ; nIndex < szContentsCount; nIndex++)
            {
                // Write line to output file
                srOutputWriteLine (szContents[nIndex]);
            }
            srOutputClose ();
            fsOutputClose ();
            // Report program success
            ConsoleWriteLine (\nThe sorted lines have been written to the output file\n\n);
        }
        // QuickSort implementation
        private static void QuickSort (ArrayList szArray int nLower int nUpper)
        {
            // Check for nonbase case
            if (nLower < nUpper)
            {
                // Split and sort partitions
                int nSplit = Partition (szArray nLower nUpper);
                QuickSort (szArray nLower nSplit );
                QuickSort (szArray nSplit + nUpper);
            }
        }
        // QuickSort partition implementation
        private static int Partition (ArrayList szArray int nLower int nUpper)
        {
            // Pivot with first element
            int nLeft = nLower + ;
            string szPivot = (string) szArray[nLower];
            int nRight = nUpper;
            // Partition array elements
            string szSwap;
            while (nLeft <= nRight)
            {
                // Find item out of place
                while (nLeft <= nRight && ((string) szArray[nLeft])CompareTo (szPivot) <= )
                    nLeft = nLeft + ;
                while (nLeft <= nRight && ((string) szArray[nRight])CompareTo (szPivot) > )
                    nRight = nRight ;
                // Swap values if necessary
                if (nLeft < nRight)
                {
                    szSwap = (string) szArray[nLeft];
                    szArray[nLeft] = szArray[nRight];
                    szArray[nRight] = szSwap;
                    nLeft = nLeft + ;
                    nRight = nRight ;
                }
            }
            // Move pivot element
            szSwap = (string) szArray[nLower];
            szArray[nLower] = szArray[nRight];
            szArray[nRight] = szSwap;
            return nRight;
        }
    }
}

  補遺關於 QuickSort C# NET為了演示 QuickSort Visual C# NET 示例應用程序實際是如何運行的我們提供了編譯好的可執行文件您可以通過編譯這些項目文件來創建自己的可執行文件單擊 Quicksort_Visual_CSharp_NETexe下載源代碼項目文件和可執行文件包

  使用應用程序啟動 Command Prompt(從開始菜單運行cmdexe使用 CD 命令將目錄更改為可執行文件所在的目錄然後運行quicksortexe

  程序將提示您提供輸入和輸出文件的名稱任何包含多行的文本文件均可使用如果需要可以使用記事本來創建一個此類文件然後該程序將對輸入文件的內容進行排序並且將其寫入輸出文件

  示例程序輸出下面是來自此 QuickSort C# NET 應用程序的一個實例的輸出此示例演示了 QuickSort 算法方法是讀取輸入文件對文件的內容進行排序然後將其寫入新的文件用戶輸入的文本以下劃線標記

  您可以查看下面的示例輸入文件 exampletxt 和輸出文件 outputtxt

  QuickSort C# NET Sample Application
Copyright (c) Microsoft Corporation All rights reserved
MSDN ACADEMIC ALLIANCE []
This example demonstrates the QuickSort algorithm by reading an input file
sorting its contents and writing them to a new file
Source: exampletxt
Output: outputtxt
The sorted lines have been written to the output file

  查看示例輸入文件exampletxt

  Visual C#
Windows Embedded
JavaScript
Speech API
ASPNET
VBScript
Windows Media
Visual Basic
NET Framework
BizTalk Server
XML Parser
Internet Explorer
Visual C#
SQL Server
Windows XP
DirectX API

  查看示例輸出文件outputtxt

  NET Framework
ASPNET
BizTalk Server
DirectX API
Internet Explorer
JavaScript
Speech API
SQL Server
VBScript
Visual Basic
Visual C#
Visual C#
Windows Embedded
Windows Media
Windows XP
XML Parser


From:http://tw.wingwit.com/Article/program/net/201311/13488.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.