简体   繁体   English

在C#中传递值

[英]passing value in c#

Dear All, I am writing a smpp application using c# and Devshock protocol.Here the mySmppClient_evDeliver_Sm method get the parameter " e " as a parameter on " Devshock.Protocol.SmppClient.Deliver_SmEventArgs e " and then using "e" we get rest of the value like: e.Params.Body.Data_Coding and e.Params.Body.Short_Message . 亲爱的所有人,我正在使用c#和Devshock协议编写smpp应用程序。在这里,mySmppClient_evDeliver_Sm方法将参数“ e ”作为“ Devshock.Protocol.SmppClient.Deliver_SmEventArgs e ”上的参数,然后使用“ e”获取其余的值,例如: e.Params.Body.Data_Codinge.Params.Body.Short_Message

private void mySmppClient_evDeliver_Sm(object sender,Devshock.Protocol.SmppClient.Deliver_SmEventArgs e)
        {
           string ShortMessage = mySmppClient.GetShortMessage(e.Params.Body.Data_Coding, e.Params.Body.Short_Message);        
           MessageBox.Show(ShortMessage);         
        }

Now my question is: 现在我的问题是:

How may i get the value Params.Body.Data_Coding and Params.Body.Short_Message without using "e" as a parameter .It will be better for me if i get the values using any object or like this below structure.How i do that? 我如何在不使用“ e”作为参数的情况下获取值Params.Body.Data_Coding和Params.Body.Short_Message 。如果我使用任何对象或以下结构体获取值,则对我来说会更好。 ?

private void mySmppClient()
{
  //declare any object or any other way let abc

   string ShortMessage=mySmppClient.GetShortMessage(abc.Params.Body.Data_Coding, abc.Params.Body.Short_Message );
   MessageBox.Show(ShortMessage);

}

I shall be very much glade to those kind heart who help me to solve this problem. 我将为那些帮助我解决这个问题的仁慈的人感到非常高兴。 Thanks in Advance Riad 在此先感谢Riad

I doesn't seem possible, at least not in a "proper" way. 我似乎不可能,至少不能以“适当”的方式。 While you could use instance or static fields to pass the method's parameters, that would be abusing the language, and you'd eventually suffer because of low code quality. 尽管您可以使用实例或静态字段来传递方法的参数,但那样会滥用该语言,并且最终将因代码质量低而受苦。 Perhaps, of course, there's a different way I didn't think of. 当然,也许我没有想到另一种方式。

Why not pass method parameters as parameters though? 为什么不将方法参数作为参数传递呢? That's what they're there for! 那就是他们在那里的目的!

Given that the content of the message you want to show is coming in as part of an event, I doubt you'll be able to get it any other way. 鉴于您要显示的消息内容是作为事件的一部分而来的,我怀疑您是否能够以其他任何方式获取它。 However, you can store the value as a member in a class, and reference the content of that class from elsewhere. 但是,您可以存储为类中的成员,并从其他位置引用该类的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM