首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

新手入门自己写的第一个Csharp程序,请看一下

2012-01-19 
新手入门自己写的第一个Csharp程序,请各位高手看一下如上所述:我写了一个程序,想请各位高手看一下,然后给

新手入门自己写的第一个Csharp程序,请各位高手看一下
如上所述:
我写了一个程序,想请各位高手看一下,然后给我一点儿意见(代码质量怎么样,可以怎么改(给点儿提示就行了)
代码如下:
/*                               ProcessMan.cs   Code   by   suRbYmiR                 *
  *                               Used   to   list   and   kill   process                   *
  *                               2007.07.20   The   First   Edition                     *
  *   */
using   System;
using   System.Diagnostics;
using   System.ComponentModel;

namespace   ProcessManger
{
        class   ProcessMan
        {
             
             
                public     void   ListProcess()
                {
                       
                       
                       
                        Process[]   LocalAll   =   Process.GetProcesses();
                        int   Len=LocalAll.Length;
                     

                        int   i=0;
                       
                        try
                        {
                                string[]   sout=DealProcesses(LocalAll,Len);

                                for   (;   i   <   Len;   i++)
                                {

                                        Console.Write( "{0}       PID   ",   sout[i]);
                                        Console.Write(LocalAll[i].Id);
                                        Console.WriteLine();


                                }
                        }


                        catch   (Win32Exception   )
                        {
                                return;
                        }
                }
                //This   method   is   used   to   deal   with   the   string   array   process.tosting(),that 's   to   say,pump   the   name   and   throw   other   useless   things;
                public     string[]   DealProcesses(Process[]   ob,int   Len)
                {
                       
                        int[]   itemp   =   new   int[Len];
                        int[]   ilen   =   new   int[Len];
                        string[]   stemp   =   new   string[Len];
                        for   (int   i   =   0;   i   <   Len;   i++)
                        {
                                itemp[i]   =   ob[i].ToString().IndexOf( "( ");
                                ilen[i]   =   ob[i].ToString().Length   -   itemp[i];
                                stemp[i]   =   ob[i].ToString().Substring(itemp[i],   ilen[i]);
                        }
                        return   stemp;
                }
        }
        class   ProcessManDemo
        {

                public   static   void   Main(string[]   args)
                {

                       
                        int   pid;
                        ProcessMan   myProcessMan   =   new   ProcessMan();
                        if   (args.Length==0)
                        {
                                Console.WriteLine( "The   Usage: ");


                                Console.WriteLine( "To   list   processes:                 ProcessMan   -l ");
                                Console.WriteLine( "To   kill   process:                     ProcessMan   -k   pid ");
                               
                                return;
                        }
                        if   (args[0]== "-l ")  
                        myProcessMan.ListProcess();
                if   (args[0]   ==   "-k ")
                {
                        pid   =   Convert.ToInt32(args[1]);
                        Process   proToKill   =   Process.GetProcessById(pid);
                        proToKill.Kill();
                }
           
                       
                }
        }
}
                   
请各位多多指教.

[解决办法]
注释少了,如果能让别人不去了解关于进程的知识就能看懂代码的话,就好了.
命名问题:listprocess(从字面意思看是列出进程),dealprocess(处理进程,是做什么处理getpid?)processman(从类名看不出是什么用途)


热点排行