小编Phy*_*dha的帖子

C#方法命名约定:ToSomething vs. AsSomething

当我为业务逻辑对象编写一些扩展方法时,我遇到了重命名转换方法的问题.someObject.ToAnotherObject()广泛使用会很好object.ToString().

但是,例如,LINQ混合了两种变体,我找不到它们之间的区别.ToDictionary(),ToList(),AsParallel(),AsQueryable(),...

这两个命名约定之间有什么区别,我应该知道如何决定是否使用我自己的类?

c# naming-conventions

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

什么是回收ListView中这种看不见的性能食物细胞?

所以我的Xamarin.Forms应用程序(在Android上)使用了一个性能问题ListView.原因是,因为我在ListView中使用了一个非常复杂的自定义控件ItemTemplate.

为了提高性能,我在自定义控件中实现了许多缓存功能,并将ListView设置CachingStrategyRecycleElement.

表现并没有好转.所以我试图找出原因是什么.

我终于发现了一些非常奇怪的bug并将其隔离在一个新的空应用中.代码如下:

MainPage.xaml中

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:c="clr-namespace:ListViewBug.Controls"
             xmlns:vm="clr-namespace:ListViewBug.ViewModels"
             x:Class="ListViewBug.MainPage">
    <ContentPage.BindingContext>
        <vm:MainViewModel />
    </ContentPage.BindingContext>

    <ListView ItemsSource="{Binding Numbers}" CachingStrategy="RetainElement"
              HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
              HasUnevenRows="True">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <c:TestControl Foo="{Binding}" />
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)

TestControl.cs

public class TestControl : Grid
{
    static int id = 0;
    int myid;

    public static readonly BindableProperty FooProperty = BindableProperty.Create("Foo", typeof(string), typeof(TestControl), "", BindingMode.OneWay, null, (bindable, oldValue, newValue) =>
    {
        int sourceId = ((TestControl)bindable).myid;
        Debug.WriteLine(String.Format("Refreshed Binding on TestControl …
Run Code Online (Sandbox Code Playgroud)

c# xaml listview xamarin.android xamarin.forms

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

在Visual Studio 2013中,断点条中的这个黑色箭头形符号是什么意思?

不知何故,我的源代码中的一行标有一个指向右侧的黑色箭头形图标.我熟悉书签和断点,但我找不到关于这一点的线索.它是下面屏幕截图中的最顶层图标.

这个符号的目的是什么?

未知图标的屏幕截图

c# ide visual-studio visual-studio-2013

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

为什么我的WebClient大部分时间都会返回404错误,但并非总是如此?

我想在我的程序中获取有关Microsoft Update的信息.但是,服务器在大约80%的时间返回404错误.我将有问题的代码归结为此控制台应用程序:

using System;
using System.Net;

namespace WebBug
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    WebClient client = new WebClient();
                    Console.WriteLine(client.DownloadString("https://support.microsoft.com/api/content/kb/3068708"));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                Console.ReadKey();
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当我运行代码时,我必须经历几次循环,直到得到实际响应:

远程服务器返回错误:(404)未找到.
远程服务器返回错误:(404)未找到.
远程服务器返回错误:(404)未找到.
<div kb-title title ="客户体验和诊断遥测更新[...]

我可以随时打开并强制刷新(Ctrl + F5)我浏览器中的链接,但它会显示正常.

问题发生在具有两个不同互联网连接的两台不同机器上.
我也使用Html Agility Pack测试了这个案例,但结果相同.其他网站不会出现
此问题.(根部工作正常100%)https://support.microsoft.com

为什么我会得到这个奇怪的结果?

c# http-status-code-404 web

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