小编Yoa*_*oav的帖子

在另一个属性设置器中使用属性值

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

c# properties .net-3.5

2
推荐指数
2
解决办法
4318
查看次数

如何在Labelary中使用BMP到ZPL的ASCII HEX优化

我想编写一个将位图图像转换为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)

.net c# zpl

2
推荐指数
1
解决办法
2222
查看次数

Un-Threaded比线程更快

我有一个应用程序需要.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)

c# performance multithreading

1
推荐指数
1
解决办法
107
查看次数

Visual Studio警告:永远不会分配x

我有以下大块的代码正在使用?? 初始化操作员:

    private string _name;
    public string Name
    {
        get { return _name ?? string.Empty; }
    }
Run Code Online (Sandbox Code Playgroud)

我猜这个代码是有效的,因为它有效,但是我在错误列表中收到以下警告:

"_name"永远不会被赋值,并且始终将其默认值设置为null

有没有办法对此进行Visual Studio停止警告?

c#

0
推荐指数
1
解决办法
1328
查看次数

c int comparrison for finish loop

我有以下函数,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.
我的形象 我在这里错过了什么?

c int do-while

0
推荐指数
1
解决办法
54
查看次数

标签 统计

c# ×4

.net ×1

.net-3.5 ×1

c ×1

do-while ×1

int ×1

multithreading ×1

performance ×1

properties ×1

zpl ×1