ushort与short的区别

 ushort:0-65535(范围),无符号16位整数,.net framework类型--System.UInt16

short:-32768-32767,有符号16位整数,.net framework类型--System.Int16

 

XML读写文件,删除节点复习

public static void Delete(string path,string boxNum)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(path);

XmlNode rootXml = doc.SelectSingleNode("/BoxTable");  //找到这个节点

if (rootXml.HasChildNodes) //如果存在子节点
{
XmlNodeList xnls = rootXml.ChildNodes;
foreach (XmlNode xn in xnls)
{
XmlElement xe = (XmlElement)xn;
if (xe.GetAttribute("BoxNumber") == boxNum)
{
xn.ParentNode.RemoveChild(xn);

//xn.RemoveAll(); 这只能删除这个节点的所有属性,并不能删除这个节点
}
}
}
doc.Save(path);
}
catch(Exception e)
{

}
}

 unsafe的概念

使用unsafe的时候:(要注意一定要点击项目属性---把标红的那项打上勾)

熟悉某项目代码---零碎小知识总结

代码:

class ShortClass
{
//ushort str = 0x11fffff;

public void show()
{
unsafe
{
int[] arry = new int[10];
for (int i = 0; i < arry.Length; i++)
{
arry[i] = i;
}

fixed (int* p = arry)
{
for (int i = 0; i < arry.Length; i++)
{
Console.WriteLine(p[i]);
}
}
}
}
}

 

fixed关键字:

fixed 语句禁止垃圾回收器重定位可移动的变量。

fixed 语句只能出现在不安全的上下文中。

Fixed 还可用于创建固定大小的缓冲区。

fixed 语句设置指向托管变量的指针并在 statement 执行期间“钉住”该变量。

如果没有 fixed 语句,则指向可移动托管变量的指针的作用很小,因为垃圾回收可能不可预知地重定位变量。

C# 编译器只允许在 fixed 语句中分配指向托管变量的指针。

 

相关文章:

  • 2021-12-31
  • 2022-02-20
  • 2022-12-23
  • 2021-06-06
  • 2021-11-13
  • 2020-10-19
  • 2018-06-24
  • 2021-11-07
猜你喜欢
  • 2021-09-14
  • 2021-11-24
  • 2021-07-23
  • 2021-11-13
  • 2021-07-09
  • 2022-02-21
  • 2018-11-23
相关资源
相似解决方案