当前位置:编程学习 > C#/ASP.NET >>

c#中如何将俩个private合并?

俩个不同的程序,其中想让第一个程序在特定的情况下使用另外的一个功能
就是相当把俩代码合并,但是其中有:
private static void TimeEvent(object source, ElapsedEventArgs e)
private static string CmdPing(string strIp)
请问如何将他们合并?

新手上路,如果表达不准,请多包涵.谢谢高手解答.


比如:
using System;
using System.Timers;
namespace ConsoleApplication1
{
    class Class1
    {
        [STAThread]
        static void Main(string[] args)
        {
            System.Timers.Timer aTimer = new System.Timers.Timer();
            aTimer.Elapsed += new ElapsedEventHandler(TimeEvent);
            aTimer.Interval = 1000;
            aTimer.Enabled = true;
            Console.WriteLine("程序执行中,回车自动结束程序...");
            Console.ReadLine();
        }
        private static void TimeEvent(object source, ElapsedEventArgs e)
        {
            int intSecond = e.SignalTime.Second;
            int iSecond = 5;
            if (intSecond == iSecond)
            {
                Console.WriteLine("每秒钟的开始执行一次!");
            }
        }
    }
}



using System;
using System.Diagnostics;
namespace ZZ
{
     class ZZConsole
     {
         [STAThread]
         static void Main(string[] args)
         {    
              string ip = "192.192.132.229";
              string strRst = CmdPing(ip);
              Console.WriteLine(strRst);
              Console.ReadLine();
         }
         private static string CmdPing(string strIp)
         {
              Process p = new Process();
              p.StartInfo.FileName = "cmd.exe";
              p.StartInfo.UseShellExecute = false;
              p.StartInfo.RedirectStandardInput = true;
              p.StartInfo.RedirectStandardOutput = true;
              p.StartInfo.RedirectStandardError = true;
              p.StartInfo.CreateNoWindow = true;
              string pingrst;
              p.Start();
              p.StandardInput.WriteLine("ping -n 1 "+strIp);
              p.StandardInput.WriteLine("exit");
              string strRst = p.StandardOutput.ReadToEnd();
              if(strRst.IndexOf("(0% loss)")!=-1)
                   pingrst = "连接";
              else if( strRst.IndexOf("Destination host unreachable.")!=-1)
                   pingrst = "无法到达目的主机";
              else if(strRst.IndexOf("Request timed out.")!=-1)
                   pingrst = "超时";
              else if(strRst.IndexOf("Unknown host")!=-1)
                   pingrst = "无法解析主机";
              else
                   pingrst = strRst;
              p.Close();
              return pingrst;
         }
     }
} --------------------编程问答-------------------- 再次求问 --------------------编程问答-------------------- 2个不同的命名空间啊 改成public 利用委托调用吧 --------------------编程问答-------------------- 是俩个都改成PUBLIC吗?
我只是想在一个PRIVATE中再使用一个PRIVATE

谢谢解答
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,