小编use*_*369的帖子

StreamReader读取行范围

让我说我有一个文件,想要阅读这些行,它是:

   while( !streamReader.EndOfStream ) {
        var line = streamReader.ReadLine( );
   }
Run Code Online (Sandbox Code Playgroud)

我如何只读取一系列行?像只有10到20的读数线.

c# streamreader

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

仅在一个对象上设置属性

如何创建像RadioButton这样的布尔属性?你知道,就像RadioButton一样,只能选择一个吗?

比如下面的例子.

当我将一个Employee设置IsResponsiblePerson为true时,它应该将所有其他Employee 设置为false.不使用循环.

var list = new ObservableCollection<Employee>();

public class Employee
{
    public string Name{get;set;}
    public string Surname{get;set;}
    public bool IsResponsiblePerson{get;set;}
}
Run Code Online (Sandbox Code Playgroud)

c#

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

Azure DevOps 对发布阶段进行排序

如何订购不同的部署环境。仅用于显示目的。目前,我们的立场是这样的:

在此处输入图片说明

我希望它看起来像这样:

开发--测试-验收--生产

我已经编辑了发布管道并向上移动了开发,但是在保存和返回时它仍然不是我想要的顺序。 在此处输入图片说明

azure-devops azure-pipelines azure-pipelines-release-pipeline

6
推荐指数
3
解决办法
2427
查看次数

仅绑定日期和时间

我有2个控件:

DatePicker:仅用于日期
文本框与TimeMask:仅用于时间

它们都链接到相同的属性,DateTime EffectiveDate 但是问题是当我更改DatePicker上的Date时,它将TimeTextBox中的Time更改回12:00。

我知道原因,但是有什么最好的解决方案可以让它们分开工作但绑定到同一属性?

我试图采用当前时间并在set属性中建立一个新的Date,但总是以溢出错误告终。

c# data-binding wpf datepicker mvvm

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

与MaxValue的日期比较不起作用

我有一个可以为null的Date属性BoughtDate.我正在尝试以下方法:

if( item.BoughtDate.Value.Equals( DateTime.MaxValue) ) item.BoughtDate= null;
Run Code Online (Sandbox Code Playgroud)

还试过这个:

if( item.BoughtDate.Equals( DateTime.MaxValue) ) item.BoughtDate=null;
Run Code Online (Sandbox Code Playgroud)

调试时,我BoughtDateDateTime.MaxValue似乎一模一样-但它说,这是不一样的(不设置我item.BoughtDate为null)

为什么我的比较不起作用?

c# datetime

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

抛出错误而不是返回null.为什么?

我有时会收到一个错误:

There is not a header with name UserName and namespace http://www.website.com/ in the message.
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪

System.ServiceModel.Channels.MessageHeaders.GetHeader [T](String name,String ns,String [] actors)Common.Utilities.WCF.WcfCallContext.TryGetHeader(String key)Common.Utilities.WCF.WcfCallContext.get_UserName()

这是2种方法:

    private static string TryGetHeader( string key )
    {
        try
        {
            return GetHeader( key );
        }
        catch
        {
            return null;
        }
    }

    private static string GetHeader( string key )
    {
        var headers = OperationContext.Current.IncomingMessageHeaders;
        var value = headers.GetHeader<string>( key, "http://www.website.com/", "Project" );
        return value;
    }
}
Run Code Online (Sandbox Code Playgroud)

所以TryGetHeader(使用try和catch)调用GetHeader.显然它打破了:

var value = headers.GetHeader<string>( key, "http://www.website.com/", "Project" ); …
Run Code Online (Sandbox Code Playgroud)

c#

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

PowerShell递归删除目录中小于500bytes的文件

任何人都可以通过Powershell脚本来帮助我。我已经在线搜索了,无法获得准确的答案。我需要一个脚本来递归删除文件夹中所有扩展名为.stat且小于500bytes的文件。然后按回车键将继续删除所有文件

powershell

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

Kusto 查询语言拆分 @ 字符并取最后一项

如果我有一个字符串,例如:“this.is.a.string.and.I.need.the.last.part”我试图在最后一个“.”之后获取字符串的最后一部分,在这个案例是“部分”我如何实现这一目标?我尝试的一种方法是将字符串拆分为“.”,我得到一个数组,但是我不知道如何检索数组中的最后一项。

| extend ToSplitstring = split("this.is.a.string.and.I.need.the.last.part", ".") 
Run Code Online (Sandbox Code Playgroud)

给我:

["this", "is","a","string","and","I","need","the","last", "part"]
Run Code Online (Sandbox Code Playgroud)

第二次尝试我试过这个:

| extend ToSubstring = substring(myString, lastindexof(myString, ".")+1)
Run Code Online (Sandbox Code Playgroud)

但是 Kusto 没有 lastindexof 的功能。

有人有提示吗?

azure azure-data-explorer

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

将 TabItem 样式更改为 TabControl.ItemTemplate

有人可以帮助我。我已经为 TabItem 标题编写了样式。但是因为我的 TabItem Header 是绑定的,所以我需要使用 TabControl.ItemTemplate 而不是 TabItem Header

那么我如何开始在 TabControl.ItemTemplate 上获得与 TabItem 相同的样式

所以我有这个:

<TabItem Header="Tab1" Style="{StaticResource TabStyle}">
</TabItem>
Run Code Online (Sandbox Code Playgroud)

现在我有这个:

<TabControl.ItemTemplate>
  <!-- this is the header template-->
  <DataTemplate>
     <TextBlock Text="{Binding Person}" />
  </DataTemplate>
</TabControl.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)

这是原始 TabItem 的样式:

<Style x:Key="TabStyle" TargetType="{x:Type TabItem}">
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="VerticalContentAlignment" Value="Center"/>
    <Setter Property="HorizontalContentAlignment" Value="Center"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TabItem}">
                <Border  Padding="3">
                    <Grid Name ="grid" Height="24">
                        <Border Name="BorderName" 
                                CornerRadius="12,12,12,12"                           
                                Background="{TemplateBinding Background}" 
                                BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}"     />
                        <Rectangle Name="TabItemBackgorund" 
                                RadiusX="12"
                                RadiusY="12" 
                                Fill="{StaticResource TabItemBackgroundBrush}"> …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml

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

通用任务方法实现

我有一个继承自 ViewModelBase 的 ViewModel。目前我在 ViewModel 中调用我的服务,如下所示:

private void Login(string _username,  string _password)
{
    Task.Run(async () =>
    {
      var isLoginSuccess = await _authenticationDataService.Login(_username, _password);
      if (isLoginSuccess == true) { }
    });
}
Run Code Online (Sandbox Code Playgroud)

在我的 AuthenticarionService 中,它看起来像这样:

  public async Task<bool> Login(string username, string password)
    {
        Token = await GetAPIToken(username, password);
        return true;
    }

    private static async Task<string> GetAPIToken(string userName, string password)
    {
       //Blah blah blah wont bore you with the detail
    }
Run Code Online (Sandbox Code Playgroud)

现在我想要的是在我的 ViewModelBase 中放置一个通用的 Task 方法,它将运行我传递给它的任何“awaitables”并返回一个通用结果(我可以在我的视图模型中正确地转换结果)。

这样我就可以做这样的事情:

private void Login(string _username,  string …
Run Code Online (Sandbox Code Playgroud)

c# generics task mvvm viewmodel

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

String中的'#'运算符

我有一段代码,我想弄清楚hash(#)字符串内部是什么.
以下是这段代码.

var key = string.Format( "{0}#{1}#{2}", value1, value2, value3);

if ( !instance.Map.ContainsKey( key ) )
{
   throw new Exception("Dear Customer, your  order cant be identified.");
}
Run Code Online (Sandbox Code Playgroud)

我不认为我曾经使用#C#

如果我没有提供value3它仍然找到钥匙.因此我认为#意味着强制性或部分性.

c# string

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