我Class需要property根据另一个设置一个值:
public class Quantities
{
private int _quant;
public int Quant
{
get { return _quant; }
set
{
if (Unit == "K")
{
_quant = value / 1000;
}
else
{
_quant = value;
}
}
}
public string Unit { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
根据我做的几个测试,它工作正常,但我仍然不知道这样做是否安全.
是否有可能在编译器(或JIT)知道它应该分配第一个Quant Property之前进行评估?Unit PropertyUnit Property
我想编写一个将位图图像转换为zpl的代码.我找到了以下代码:
string bitmapFilePath = @"D:\Demo.bmp";
int w, h;
Bitmap b = new Bitmap(bitmapFilePath);
w = b.Width; h = b.Height;
byte[] bitmapFileData = System.IO.File.ReadAllBytes(bitmapFilePath);
int fileSize = bitmapFileData.Length;
// The following is known about test.bmp. It is up to the developer
// to determine this information for bitmaps besides the given test.bmp.
int bitmapDataOffset = int.Parse(bitmapFileData[10].ToString()); ;
int width = w; // int.Parse(bitmapFileData[18].ToString()); ;
int height = h; // int.Parse(bitmapFileData[22].ToString()); ;
int bitsPerPixel = int.Parse(bitmapFileData[28].ToString()); // Monochrome image required!
int bitmapDataLength …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序需要.CSV在应用程序启动时读取非常大的文件并将每行转换为object.这些是读取文件的方法:
public List<Aobject> GetAobject()
{
List<Aobject> Aobjects = new List<Aobject>();
using (StreamReader sr = new StreamReader(pathA, Encoding.GetEncoding("Windows-1255")))
{
string line;
while ((line = sr.ReadLine()) != null)
{
string[] spl = line.Split(',');
Aobject p = new Aobject { Aprop = spl[0].Trim(), Bprop = spl[1].Trim(), Cprop = spl[2].Trim() };
Aobjects.Add(p);
}
}
return Aobjects;
}
public List<Bobject> GetBobject()
{
List<Bobject> Bobjects = new List<Bobject>();
using (StreamReader sr =
new StreamReader(pathB, Encoding.GetEncoding("Windows-1255")))
{
//parts.Clear();
string line;
while ((line = …Run Code Online (Sandbox Code Playgroud) private string _name;
public string Name
{
get { return _name ?? string.Empty; }
}
Run Code Online (Sandbox Code Playgroud)
我猜这个代码是有效的,因为它有效,但是我在错误列表中收到以下警告:
"_name"永远不会被赋值,并且始终将其默认值设置为null
有没有办法对此进行Visual Studio停止警告?
我有以下函数,do while里面有一个循环:
void GetFiveNumericValues()
{
int validationResult;
char input[5];
do
{
printf("Please enter 5 digits:\n");
validationResult = scanf("%s", &input);
printf("Validation result: %d\n", validationResult);
} while (validationResult != 1);
// while (!(validationResult == 1));
// while (validationResult > 1 || validationResult < 1);
}
Run Code Online (Sandbox Code Playgroud)
即使在时,循环也没有完成validationResult == 1.
我在这里错过了什么?