我想我理解为什么IEnumerable<T>继承IEnumerable之后,阅读帖子后:
为什么IEnumerable<T>从IEnumerable继承?
但是,我不确定在应用2个通用接口时如何最好地实现非泛型方法?这是我正在编写的代码示例:
public interface IComponentA { /* ... Interface A Code ... */ }
public interface IComponentB { /* ... Interface B Code ... */ }
public class ComponentModel: IEnumerable<IComponentA>, IEnumerable<IComponentB>
{
public ComponentModel() { }
private List<IComponentA> ListOfComponentA = new List<IComponentA>();
private List<IComponentB> ListOfComponentB = new List<IComponentB>();
// ... Some public methods to add and remove components (for A and B).
IEnumerator<IComponentA> IEnumerable<IComponentA>.GetEnumerator()
{
return ListOfComponentA.GetEnumerator();
}
IEnumerator<IComponentB> IEnumerable<IComponentB>.GetEnumerator()
{
return ListOfComponentB.GetEnumerator(); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用带有Prime符号的字符串,但我遇到了String.StartsWith方法的一些问题.为什么以下代码抛出异常?
string text_1 = @"123456";
string text_2 = @"?ABCDEF";
string fullText = text_1 + text_2;
if (!fullText.StartsWith(text_1))
{
throw new Exception("Unexplained bad error.");
}
Run Code Online (Sandbox Code Playgroud)
我怀疑这个问题是因为这个Prime符号(char)697被视为重音,因此正在改变它之前的字母.(我不认为它应该是 - 它应该是主要符号,所以不应该改变它前面的数字).我不确定如何测试这个.我确实尝试了这个答案中提出的方法,但它返回false:
IsLetterWithDiacritics(text_1[5]) // == False
IsLetterWithDiacritics(fullText[5]) // == False
IsLetterWithDiacritics(fullText[6]) // == False
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
任何人都知道为什么ChartArea.BackImage是string类型的属性?对于这种类型的Image属性来说,它是否更有意义?
或者换句话说,如何将ChartArea的背景图像设置为在运行时生成的图像(例如,从GraphicPath对象)?
欢迎提出建议,谢谢.
我想问一下延迟加载。我经常读到我们应该拒绝它,但我为什么要加载可能从未使用过的数据?
作为讨论的一个例子,让我们使用一个Customer:
-Id
-Title
-FormOfAddress
-FirstName
-LastName
-Picture*
-DOB
-Phone
-Mobile
-Address*/Billing Address*
-Id
-Street
-Number
-Country*
-Id
-Name
-Zipcode
-Bankdetails*
-Id
-AccountHolder
-AccountNumber
-Bank*
-Id
-Name
-BankCode
-IBAN
Run Code Online (Sandbox Code Playgroud)
*根据座右铭“仅加载您需要的内容” ,标记我将延迟加载的对象。
好吧,我的问题似乎还不够清楚,所以这里可能是我想知道的更好的表述:
我想知道为什么大多数人都劝阻懒惰加载,是因为他们不能使用它还是它有非常糟糕的缺点?
我正在尝试在XML 文件中保存和加载ImageSource(或BitmapSource)。快速浏览一下 SO 给了我这个答案。
看起来不错,所以我试了一下,但我得到了一个奇怪的结果。
当我尝试此代码时,一切正常:
BitmapSource testImgSrc = new WriteableBitmap(new BitmapImage(new Uri("pack://application:,,,/MyNameSpace;component/Images/MyImg.png")));
BackgroundImage = testImgSrc;
Run Code Online (Sandbox Code Playgroud)
但是当我尝试这段代码时,图像根本没有出现:
BitmapSource testImgSrc = new WriteableBitmap(new BitmapImage(new Uri("pack://application:,,,/MyNameSpace;component/Images/MyImg.png")));
string testImgStr = ImageToBase64(testImgSrc);
BitmapSource testImg = Base64ToImage(testImgStr);
BackgroundImage = testImg;
Run Code Online (Sandbox Code Playgroud)
似乎没有任何错误或异常。当逐步执行代码时,BackgroundImage它看起来像是被设置为一个有效的图像对象。
我的 WPF 表单有一个图像控件,它的源代码绑定到一个返回属性结果的BackgroundImage属性。我猜绑定工作正常,因为第一个测试按预期工作。
谁能帮我理解为什么第二个测试没有显示我的图像?
在这个MSDN页面中,它说:
警告:
如果重写GetHashCode方法,则还应该重写Equals,反之亦然.如果在对两个对象进行相等性测试时,重写的Equals方法返回true,则重写的GetHashCode方法必须为两个对象返回相同的值.
我也看到了许多类似的建议,我可以理解,当重写Equals方法时,我也想要覆盖GetHashCode.据我所知,GetHashCode与哈希表查找一起使用,这与等式检查不同.
这是一个帮助解释我想问的例子:
public class Temperature /* Immutable */
{
public Temperature(double value, TemperatureUnit unit) { ... }
private double Value { get; set; }
private TemperatureUnit Unit { get; set; }
private double GetValue(TemperatureUnit unit)
{
/* return value converted into the specified unit */
}
...
public override bool Equals(object obj)
{
Temperature other = obj as Temperature;
if (other == null) { return false; }
return (Value == other.GetValue(Unit));
}
public …Run Code Online (Sandbox Code Playgroud) c# ×6
.net ×1
asp.net ×1
charts ×1
diacritics ×1
equality ×1
escaping ×1
gethashcode ×1
image ×1
lazy-loading ×1
mschart ×1
mvvm ×1
startswith ×1
string ×1
wpf ×1