就像在主题中一样:我想从文件(从流)读取数据到内存(memorystream)以提高我的应用程序速度.怎么做?
为什么我使用:
struct MyStruct
{
[FieldOffset (0)] public uint Data;
[FieldOffset (0)] public byte Something;
}
public MyStruct (uint pData)
{
Data = pData; // setting Data field also sets Something field
}
Run Code Online (Sandbox Code Playgroud)
C#说我需要分配'Something'字段:/我知道我可以做一个"构造函数:this()"但是编译器应该知道'Data'字段包含'Something'字段.
所以,我应该先调用无参数构造函数,这是唯一的方法吗?
是否可以为对象浏览器(VS 2010)中的set和get asssessors添加xml-comments?
/// <summary>
/// Something abot property.
/// </summary>
public bool IsSomething
{
// get description
get
{
return isSomething;
}
// set description
set
{
// do some work
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个结构:
public struct Decibel
{
public readonly double Value;
public Decibel (double value)
{
Value = value;
}
public static implicit operator Decibel (double decibels)
{
return new Decibel (decibels);
}
public static implicit operator double (Decibel decibels)
{
return decibels.Value;
}
}
Run Code Online (Sandbox Code Playgroud)
现在我可以这样做:
bool x = new Decibel (0) < new Decibel (1);
Run Code Online (Sandbox Code Playgroud)
似乎编译器足够智能转换Decibel为double,然后使用<运算符进行双打?
我有不同的struct名字Duration,包装TimeSpan.它有隐式转换为TimeSpan向/从Duration,但<和>运营商都没有工作了.
c#只识别原始类型之间的转换吗?
我Marshal.GlobalHAlloc用来分配内存.正如文档所说:"此方法从Kernel32.dll公开Win32 LocalAlloc函数." GlobalAlloc的文档说它将是8字节对齐,但LocalAlloc没有说任何关于对齐.
例如,我想分配1024个字节并确保它与16对齐.当我分配1024 + 16个字节然后检查指针%16时它会工作吗?如果结果为0则意味着内存对齐,当它不为0时,我只是增加指针以符合我的期望.问题是我不知道,如果我有对齐指针它真的在物理内存中对齐?
我正在尝试制作一个发送电子邮件的简单应用程序.我用MailMessage和SmtpClient上课.SmpClient需要登录名和密码才能工作.
我有外部.DLL文件,里面有快速汇编程序代码.调用此.DLL文件中的函数以获得最佳性能的最佳方法是什么?
<Binding Path="AttachmentName" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<valid:AttachmentNameValidationRule ValidationStep="RawProposedValue" ValidatesOnTargetUpdated="True"/>
</Binding.ValidationRules>
</Binding>
Run Code Online (Sandbox Code Playgroud)
验证器检查输入的值是否采用正确的格式:file.extension。不幸的是,当控件 IsEnabled == false 时 textBox 是红色的(因为内容是“”)。
知道如何禁用验证吗?用 x:referense 尝试了一些东西并将 UIElement 传递给验证器,但没有用。
可能重复,我有构造函数XYZ(字符串名称)的抽象类.我也有从该抽象类继承的类.如何强制继承类调用base(字符串名称)?现在我可以使用new Inherited(),它不会调用base construcotr.我想强制用户在继承的类中实现默认构造函数.
为什么VS抱怨这个终结者?
VS 2017 - 15.3.5
Microsoft Code Analysis 2017 - 2.3.0.62003
using System;
namespace ConsoleApp
{
class DisposableClass : IDisposable
{
#if DEBUG
~DisposableClass() // CA1821 Remove empty Finalizers
{
System.Diagnostics.Debug.Fail("Forgot Dispose?");
}
#endif
public void Dispose()
{
#if DEBUG
GC.SuppressFinalize(this);
#endif
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Run Code Online (Sandbox Code Playgroud) c# ×9
.net ×2
.net-core ×1
dllimport ×1
email ×1
loadlibrary ×1
memory ×1
security ×1
smtpclient ×1
stream ×1
struct ×1
unmanaged ×1
winforms ×1
wpf ×1
xml-comments ×1