主程序:  aaa a = new aaa();
          a.hx();或者你写个方法 返回 string或者你需要的类型
比如: public string hx(){  return  string的数据; }

解决方案 »

  1.   

    public class aaa
    {
       public string hx()
       {
          string a=这里是一个接收串口数据,想在这里将接收到的数据传回到主程序里
          return a;
       }
    }
    主程序:  
    aaa a = new aaa();
    string result=a.hx();
      

  2.   

    传参就可以了呀
    public class aaa
    {
       public void hx(string[] str)
       {
          这里是一个接收串口数据,想在这里将接收到的数据传回到主程序里
          return str;
       }
    }
    主程序:  aaa a = new aaa();
              string[] str=a.hx();
              
      

  3.   

    用委托吧,
    在AAA里定义一个delegate,在new这个aaa后把主程序的一个过程绑定到对应的委托上,
    当在aaa里调用这个委托时不会触发主程序的那个方法。
      

  4.   

    传参就可以了呀
    public class aaa
    {
       public string[] hx()
       {
          这里是一个接收串口数据,想在这里将接收到的数据传回到主程序里
          return str;
       }
    }
    主程序:  aaa a = new aaa();
              string[] str=a.hx();
              
      

  5.   

    可以的
    public class intterface
    {
       public string out()
       {
          string a=....     
          return a;
       }
    }
    调用  
    intterface a = new intterface();
    string result=a.out();
      

  6.   

    可用 Delegate 实现,像这样:
    using System;// delegate declaration
    delegate void MyDelegate();public class MyClass 
    {
       public void InstanceMethod() 
       {
          Console.WriteLine("A message from the instance method."); 
       }   static public void StaticMethod() 
       {
          Console.WriteLine("A message from the static method.");
       }
    }public class MainClass 
    {
       static public void Main() 
       {
          MyClass p = new MyClass();      // Map the delegate to the instance method:
          MyDelegate d = new MyDelegate(p.InstanceMethod);
          d();      // Map to the static method:
          d = new MyDelegate(MyClass.StaticMethod);
          d();
       }
    }
      

  7.   

    to  amendajing(被压迫,闭关学习!) ;要实时的哟?就是收到数据就传递信息?你那个不能实现功能!
      

  8.   

    可以在类中声明一个串用来保存接收到的数据,当用类中的函数public void hx()接收到数据后,调用另一个函数public string out()出去就可以了吧
      

  9.   

     to yyhappy(YY) 主程序要用什么方式接收这个类的信息?不能一次性的
      

  10.   

    用ref不就行了
    public class aaa
    {
       public void hx(ref string str_tem)
       {
          这里是一个接收串口数据,想在这里将接收到的数据传回到主程序里
          string str_aa = "aa";
          str_tem = str_aa;
       }
    }
    在主程序中,只要调用时
    aaa bb = new aaa();
    string str_tem = "";
    bb.hx(ref str_tem);
      

  11.   

    还有,那样的话,就可以定义返回类型为bool,这样可以判断是否成功
      

  12.   

    public string hx()
       {
          string a=这里是一个接收串口数据,想在这里将接收到的数据传回到主程序里
          return a;
       }
      

  13.   

    建议使用事件,aaa提供一个事件,供主程序使用,以决定如何处理aaa的信息。
    多数情况下,不要让aaa去操作主程序。
    public class aaa
    {
      public event EventHandler HxExecuted;
       public void hx()
       {
          if ( HxExecuted != null ){
             HxExecuted( this, EventArgs.Empty ); //通知挂接到事件链上的调用者。
          }
          这里是一个接收串口数据,想在这里将接收到的数据传回到主程序里
       }
    }主程序
     aaa a = new aaa();
     a.HxExecuted += new EventHandler( this.aaa_HxExecuted );private void aaa_HxExecuted( object sender, EventArg e ) {
      // 得到a的Hx方法执行的消息,可以处理了.
    }
      

  14.   

    UP 
    UP UP
    UP UP UP
      

  15.   

    我认为比较好的就是使用委托和事件,
    需要通知时触发一下。
    事件和委托参考
    http://blog.csdn.net/zhzuo/archive/2004/06/15/22038.aspx
    http://blog.csdn.net/zhzuo/archive/2004/06/15/22039.aspx
    如果需要可以留言。
      

  16.   

    你有不是个虚类,用属性可以看看,set {} 和 get{}