.NET XmlHelper帮助类

2021-06-29 21:06

阅读:406

标签:eof   int end   XML   帮助   cat   ons   base   ret   ++   

  public class Program
    {
        static void Main(string[] args)
        {
            Student stu1 = new Student() { Name = "okbase", Age = 10 };
            string xml = XmlHelper.Serializer(typeof(Student), stu1);
            Console.Write(xml);
            Student stu2 = XmlHelper.Deserialize(typeof(Student), xml) as Student;
            Console.Write(string.Format("名字:{0},年龄:{1}", stu2.Name, stu2.Age));
            Console.ReadKey();
        }
        public class Student
        {
            public string Name { set; get; }
            public int Age { set; get; }
        }
        /// 
        /// 将传入的字符串中间部分字符替换成特殊字符
        /// 
        /// 需要替换的字符串
        /// 前保留长度
        /// 尾保留长度
        /// 特殊字符
        /// 被特殊字符替换的字符串
        private static string ReplaceWithSpecialChar(string value, int startLen = 4, int endLen = 4, char specialChar = ‘*‘)
        {
            try
            {
                int lenth = value.Length - startLen - endLen;
                string replaceStr = value.Substring(startLen, lenth);
                string specialStr = string.Empty;
                for (int i = 0; i 

  使用方法

public class Program
    {
        static void Main(string[] args)
        {
            Student stu1 = new Student() { Name = "okbase", Age = 10 };
            string xml = XmlHelper.Serializer(typeof(Student), stu1);
            Console.Write(xml);
            Student stu2 = XmlHelper.Deserialize(typeof(Student), xml) as Student;
            Console.Write(string.Format("名字:{0},年龄:{1}", stu2.Name, stu2.Age));
            Console.ReadKey();
        }
        public class Student
        {
            public string Name { set; get; }
            public int Age { set; get; }
        }
    }

 

  

.NET XmlHelper帮助类

标签:eof   int end   XML   帮助   cat   ons   base   ret   ++   

原文地址:http://www.cnblogs.com/qzxj/p/7140522.html

上一篇:PHP--02

下一篇:Js 循环结构


评论


亲,登录后才可以留言!