我需要在服务端传输一段方法给客户端调用,但参数是客户端的,我做了个实验,没有成功,望告人指教!using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Serialization.Formatters.Binary;namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
try
{
BinaryFormatter a = new BinaryFormatter();
System.IO.MemoryStream b = new System.IO.MemoryStream();
a.Serialize(b, new Action<string>(delegate { method(null); }));
b.Position = 0;
dynamic c = a.Deserialize(b);
c.DynamicInvoke(new object[] { "ds" }); //我想传参数进去,但没用
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public static void method(string t)
{
MessageBox.Show(t);
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Serialization.Formatters.Binary;namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
try
{
BinaryFormatter a = new BinaryFormatter();
System.IO.MemoryStream b = new System.IO.MemoryStream();
a.Serialize(b, new Action<string>(delegate { method(null); }));
b.Position = 0;
dynamic c = a.Deserialize(b);
c.DynamicInvoke(new object[] { "ds" }); //我想传参数进去,但没用
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public static void method(string t)
{
MessageBox.Show(t);
}
}
}
解决方案 »
- 有些程序有分割线,分割线怎么弄的?
- bubble的attach问题
- WinForm如何做到窗体和控件同时缩放?
- 如何把一客户端的richtextbox中设定的字体和颜色发送到另一客户端的richtextbox中?
- 使用TransactionScope时出现“与基础事务管理器的通信失败”的错误
- [提问]除了VS,有无小巧一点的C#编译器????
- C#(2005)如何操作Excel
- C# 中怎么找不到下拉菜单控件, 就像 HTML 中的下拉菜单那样的
- 如何判断SQLServer中的Image表是否为空
- ?TCP client无应答时程序明显变慢,有什么办法可以加速,谢谢
- 有关C#做股票软件的问题
- visual studio 2008中的datapager如何获取当前页的索引?急,在线等...
=>
a.Serialize(b, new Action<string>(_ => method(_)));
t => method(t)敢问这属于哪块知识了
a.Serialize(b, new Action<string>(method));
BTW: t => method(t) 是 lambada 表达式, 有些语言里叫Closure
t => method(t) 意思差不多等于 var f(var t) { return method(t); } 其中的 var 由编译器根据语境来推理出适当的类型。如果第一个var推导结果为 void, 则后边 的return 去掉
如果你要远程调用,用 Remoting, 或者 WCF
这写法是什么个意思?的确可以了!
晕,是lambada吧...
你写个"_"还真没看出来- -