我有下面的代码将32位BCD值(以两个uint half提供)转换为uint二进制值.
提供的值最大为0x9999,最大值为0x99999999.
是否有更好(即更快)的方法来实现这一目标?
/// <summary>
/// Convert two PLC words in BCD format (forming 8 digit number) into single binary integer.
/// e.g. If Lower = 0x5678 and Upper = 0x1234, then Return is 12345678 decimal, or 0xbc614e.
/// </summary>
/// <param name="lower">Least significant 16 bits.</param>
/// <param name="upper">Most significant 16 bits.</param>
/// <returns>32 bit unsigned integer.</returns>
/// <remarks>If the parameters supplied are invalid, returns zero.</remarks>
private static uint BCD2ToBin(uint lower, uint upper)
{
uint binVal = 0;
if …Run Code Online (Sandbox Code Playgroud) 假设我正在使用'Job'类记录一些数据.(具有各种属性的业务对象列表,用于它的价值.)
我希望能够打印这些数据,所以我想知道是否有更优选的设计来做到这一点.我目前有两个想法 - 在Job本身上调用Print()方法,或者将Job实例传递给某种打印控制器类,例如:
job.Print();
Run Code Online (Sandbox Code Playgroud)
要么
PrintWidget pw = new PrintWidget(job);
pw.Print();
Run Code Online (Sandbox Code Playgroud)
目前,我无法设想打印此Job类中的数据以外的任何内容.但是,谁知道未来会怎样.考虑到这一点,在我想要打印的任何类上使用单独的Print()方法,或者可以处理不同类型的东西打印的一个Print控制器类会更好吗?
你会如何设计呢?提前感谢您的任何答案.
假设我有一个使用VS2008针对.NET 2.0构建和编译的WinForms应用程序.
我的理解是,在运行时,应用程序将首先尝试加载.NET 2.0 CLR(因为这是针对它编译的),无论 app.config的任何"supportedRuntime"元素中是否列出任何内容.文件.
如果找不到它,那么它将通过检查app.config等进行决定另一个版本的过程.
例如,如果在机器上安装了.NET 2/3/3.5和.NET 4.0,我有:
<supportedRuntime>V4.0</supportedRuntime>
Run Code Online (Sandbox Code Playgroud)
在app.config中,应用程序仍将选择加载并运行.NET 2.0.
那是对的吗?
谢谢.
我使用私有类的实例作为提供给stream.BeginRead操作的状态对象.(该类对我的主流读/写类是私有的.)
public class MainClass
{
// ...
private class ResponseState
{
public IResponse response;
public Stream stream;
public byte[] buffer = new byte[1024];
}
}
Run Code Online (Sandbox Code Playgroud)
可以直接通过字段访问课程.在这种情况下,我是否真的应该通过属性提供对类的访问,即使它只用于保持状态?
有兴趣知道其他人做了什么.
我有一个接口,定义了一个返回的方法IList<PropertyInfo>:
public interface IWriteable
{
IList<PropertyInfo> WriteableProperties();
}
Run Code Online (Sandbox Code Playgroud)
.
.
它以下列方式在各种(不同的)类中实现:
public abstract class Foo
{
private IList<PropertyInfo> _props;
protected Foo()
{
this._props = new List<PropertyInfo>();
foreach (PropertyInfo p in this.GetType().GetProperties())
{
if (Attribute.IsDefined(p, typeof(WriteableAttribute)))
this._props.Add(p);
}
}
#region IWriteable Members
public IList<PropertyInfo> WriteableProperties()
{
return this._props;
}
#endregion
}
public class Bar : Foo
{
public string A
{
get { return "A"; }
}
[Writeable()]
public string B
{
get { return "B"; }
}
[Writeable()] …Run Code Online (Sandbox Code Playgroud) 我编写了一个 C# 程序来接收 COM2 端口上的数据。波特率设置为115200。发送方以115200bps 的速率发送数据。我的程序偶尔会丢失几个字节。我正在调用方法从 com 端口循环ReadByte读取数据。while(true)
我有几个问题:
关于如何调试这个问题有什么想法吗?