01.C#转成xml
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml.Serialization;
using UnityEngine;
[Serializable]
public class Player
{
[XmlAttribute]
public int Id { get; set; }
[XmlAttribute]
public string Name { get; set; }
[XmlArray]
public List<int> List { get; set; }
}
void InitXml()
{
Player player=new Player();
player.Id = 100;
player.Name = "得到";
player.List=new List<int>(){1,2,3};
FileStream stream=new FileStream(Application.dataPath+"/Players",FileMode.Create,FileAccess.ReadWrite,FileShare.ReadWrite);
StreamWriter streamWriter=new StreamWriter(stream,Encoding.UTF8);
XmlSerializer xml=new XmlSerializer(typeof(Player));
xml.Serialize(stream,player);
streamWriter.Close();
stream.Close();
}
}
结果
<?xml version="1.0"?>
<Player xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Id="100" Name="得到">
<List>
<int>1</int>
<int>2</int>
<int>3</int>
</List>
</Player>
本文地址:https://blog.csdn.net/weixin_33950757/article/details/107623616
如对本文有疑问, 点击进行留言回复!!
win10系统玩游戏出现错误提示battleye launcher怎么办
vs2019报错:配置“Debug|Win32”的 Designtime 生成失败IntelliSense 可能不可用的问题
RHA TrueConnect真无线耳机怎么样 RHA TrueConnect真无线耳机评测
OnePlus Buds值得入手吗 OnePlus Buds真无线蓝牙耳机评测
雷神娜迦海妖机械键盘怎么样 雷神娜迦海妖Cherry轴机械键盘评测
Win10 Build 20185更新了什么 win10 Build 20185 的新增功能汇总
Win7工作组不可用怎么办? Win7工作组无法改动的解决办法
网友评论