以下是代码中常常用到的一些转换,整理如下,后续再不断完善:

1.string和Color的转换

//string转Color
(Color)ColorConverter.ConvertFromString((string)str);

//Color转string
((Color)value).ToString();

 

2.string和Brush的转换

//string转Brush 
Brush color = new SolidColorBrush((Color)ColorConverter.ConvertFromString((string)str));

//Brush转string
((Brush)value).ToString();

3.string和byte[]的转换

//string转byte[]
System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding();
byte[] stringBytes = converter.GetBytes(inputString);

//byte[]转string
System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding();
string outputString = converter.GetString(stringByte);

 

相关文章:

  • 2022-12-23
  • 2021-11-05
  • 2021-08-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-21
  • 2021-07-16
  • 2021-06-29
  • 2022-12-23
  • 2021-06-30
  • 2022-02-10
相关资源
相似解决方案