小编Bil*_*hmi的帖子

从一组对象中加入唯一的字符串

我有一个包含字符串的对象数组.

var values = new object[5];
values[0] = "PIZZA HUT";
values[1] = "ISLAMABAD";
values[2] = "ISLAMABAD";
values[3] = "PAKISTAN";
values[4] = "PAKISTAN";
Run Code Online (Sandbox Code Playgroud)

我想从数组中获取一串独特的元素,加入,时还需要检查字符串是否为nullOrWhiteSpace;

PIZZA HUT, ISLAMABAD, PAKISTAN. 
Run Code Online (Sandbox Code Playgroud)

目前我正在做以下事情.但是你可以看到它需要在if语句中进行大量检查.我想知道是否有更好的方法使用LINQ

string featureName = values[0] as string;
string adminboundry4 = values[1] as string;
string adminboundry3 = values[2] as string;
string adminboundry2 = values[3] as string;
string adminboundry1 = values[4] as string;


if (!string.IsNullOrWhiteSpace(adminboundry4) 
   && adminboundry4 != adminboundry1 
   && adminboundry4 != adminboundry2 
   && adminboundry4 != adminboundry3) //want to get rid of …
Run Code Online (Sandbox Code Playgroud)

c# linq c#-4.0

5
推荐指数
2
解决办法
2111
查看次数

仅将LayoutTransform应用于父级,但不应用于任何特定子级

MainWindow.XAML:

<Window x:Class="TestWPFApp.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Name="myMainWindow"
            Title="MainWindow" Width="200" Height="250">
        <Grid Name="MainGrid" SizeChanged="MainGrid_SizeChanged">
            <Grid.LayoutTransform>
                <ScaleTransform x:Name="ApplicationScaleTransform"
                            CenterX="0"
                            CenterY="0"
                            ScaleX="{Binding ElementName=myMainWindow, Path=ScaleValue}"
                            ScaleY="{Binding ElementName=myMainWindow, Path=ScaleValue}" />
            </Grid.LayoutTransform>
            <Grid VerticalAlignment="Center" HorizontalAlignment="Center" Height="150">
                <TextBlock FontSize="20" Text="Hello World" Margin="5" VerticalAlignment="Top" HorizontalAlignment="Center"/>
                <Button Content="Button" VerticalAlignment="Bottom" HorizontalAlignment="Center" Name="myButton"/>
            </Grid>
        </Grid>

    </Window>
Run Code Online (Sandbox Code Playgroud)

主窗口代码隐藏:

 public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        #region ScaleValue Depdency Property
        public static readonly DependencyProperty ScaleValueProperty = DependencyProperty.Register("ScaleValue", typeof(double), typeof(MainWindow), new UIPropertyMetadata(1.0, new PropertyChangedCallback(OnScaleValueChanged), new CoerceValueCallback(OnCoerceScaleValue)));

        private static object OnCoerceScaleValue(DependencyObject …
Run Code Online (Sandbox Code Playgroud)

c# wpf

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

标签 统计

c# ×2

c#-4.0 ×1

linq ×1

wpf ×1