我如何传递xml字符串 [英] how can i pass xml string

查看:52
本文介绍了我如何传递xml字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用c#将xml字符串传递给其他类对象.
然后,我想在我的字符串类型变量中隐藏该xml字符串.

how to pass xml string to my other class objects using c#.
and after that i want to concatinate that xml string in my string type variable.
and i need to call it when my other class will get call.

推荐答案

我认为,一种简洁的方法是使用可以设置和设置的类属性.如果要一次设置为只读,则没有其他类修改该值.

以下是Class1和Class2:
I think one of the neat approaches would be to use class properties which you can set and make readonly if you want once set then no other class modifies the value.

Below is Class1 and Class2:
//Set property MyXml for Class2 like so:
public class Class1
{
    //e.g. I do it in the constructor here:
    public Class1( String myXml )
    {
        Class2 class2 = new Class2();
        class2.MyXml = myXml;
        //we are done here!
    }
}

public class Class2
{
   //class1 properties
   public String MyXml
   {
       get;set;
   }
   
   //access this property with the "this.MyXml" anywhere inside this class (Class2)
}



更多属性?去吧:
http://msdn.microsoft.com/en-us/library/x9fsa0sw%28v = vs.80%29.aspx [ ^ ]

祝您编程愉快,
莫尔斯



More on properties? there goes it:
http://msdn.microsoft.com/en-us/library/x9fsa0sw%28v=vs.80%29.aspx[^]

Happy coding,
Morgs


这篇关于我如何传递xml字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆