以下表达式返回一个联系人 - 与几十个属性的整个联系人.这很好,但理想情况下,我希望返回只是联系人的id(contact.contactId)属性.我该怎么做呢?
var assocOrg = Contacts.Where(x => x.ContactTypeID == 2 && x.OrganizationName == "COMPANY XYZ");
Run Code Online (Sandbox Code Playgroud) 是否有内置的.NET函数或简单的转换方式:
"01234"
Run Code Online (Sandbox Code Playgroud)
至:
"\u2070\u00B9\u00B2\u00B3\u2074"
Run Code Online (Sandbox Code Playgroud)
请注意,上标1,2和3不在\ u2070-\u209F范围内,但是\ u0080-\u00FF.
我按照此处的说明使用IEnumerable定义了一个集合初始化程序:http: //msdn.microsoft.com/en-us/library/bb384062.aspx
现在,我可以在我的集合初始化程序中创建对象,并使用我的Add()方法添加它们,如下所示:
class ArrangedPanel : RectElement
{
private List<RectElement> arrangedChildren = new List<RectElement>();
public int Padding = 2;
public void Add(RectElement element)
{
arrangedChildren.Add(element);
//do custom stuff here
}
public IEnumerator GetEnumerator()
{
return arrangedChildren.GetEnumerator();
}
}
// Somewhere
debugPanel.Add(new ArrangedPanel()
{
new ButtonToggle(),
new ButtonToggle()
});
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试设置属性,例如我的"填充"字段,我会在集合初始值设定项上出错.
debugPanel.Add(new ArrangedPanel()
{
Padding = 5,
new ButtonToggle(),
new ButtonToggle()
});
Run Code Online (Sandbox Code Playgroud)
是否可以设置集合初始化器和对象初始化器?
我有一个基于TcpClient/TcpListener和SslStream的简单客户端 - 服务器应用程序.客户端可以使用X509Certificate对服务器进行身份验证,也可以在SslStream建立后通过发送用户名和密码进行身份验证.
WCF使用System.IdentityModel命名空间进行身份验证,但显然可以在任意应用程序中使用 - 这听起来很有趣.关于如何做到这一点的信息很少(或者我今天的Google foo很弱).
所以,我的问题是:我需要做什么才能将System.IdentityModel与我的应用程序集成?我不确定我是否需要所有的ClaimSet内容,但如果用户只使用他们的Windows帐户或任何其他提供的身份验证机制登录就会很好.(不幸的是,我不能只是切换到WCF但必须使用自定义协议,尽管我可以在必要时对其进行一些更改.)
Guid mainfolderid = (main.GetValue(""));
Run Code Online (Sandbox Code Playgroud)
哪里main是动态实体.
我怎样才能将上面提到的转换main.GetValue("")成System.Guid?
错误说
无法将类型对象隐式转换为"System.Guid".
鉴于以下代码:
static void Main()
{
Console.WriteLine(typeof(MyEnum).BaseType.FullName);
}
enum MyEnum : ushort
{
One = 1,
Two = 2
}
Run Code Online (Sandbox Code Playgroud)
它输出System.Enum,这意味着这里的冒号与继承无关,它只是指定了枚举的基本类型,对不对?
但是,如果我更改我的代码如下:
enum MyEnum : UInt16
{
One = 1,
Two = 2
}
Run Code Online (Sandbox Code Playgroud)
我会得到一个编译错误.为什么?是不是UInt16和ushort一样吗?
是否可以执行作为资源包含在项目中的exe文件?我可以将文件作为字节数组获取并在内存中执行吗?
我不想将文件写入临时位置并在那里执行.我正在寻找一种解决方案,我可以在内存中执行它.(这不是.NET程序集.)
我有以下XAML:
<UserControl x:Class="EMS.Controls.Dictionary.TOCControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:EMS.Controls.Dictionary.Models"
xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase"
x:Name="root" >
<TreeView
x:Name="TOCTreeView"
Background="White"
Padding="3,5"
ContextMenuOpening="TOCTreeView_ContextMenuOpening"
ItemsSource="{Binding Children}" BorderBrush="{x:Null}" >
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=Children, Mode=OneTime}">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<!--<ColumnDefinition Width="Auto"/>-->
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!--<CheckBox VerticalAlignment="Center" IsChecked="{Binding IsVisible}"/>-->
<ContentPresenter Grid.Column="0" Height="16" Width="20"
Content="{Binding LayerRepresentation}" />
<!--<ContentPresenter Grid.Column="1" >
<ContentPresenter.Content>
Test
</ContentPresenter.Content>
</ContentPresenter>-->
<TextBlock Grid.Column="2" FontWeight="Normal" Text="{Binding Path=Alias, Mode=OneWay}" >
<ToolTipService.ToolTip>
<TextBlock Text="{Binding Description}" TextWrapping="Wrap"/>
</ToolTipService.ToolTip>
</TextBlock>
</Grid>
<HierarchicalDataTemplate.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Path=Children, Mode=OneTime}">
<!--<DataTemplate>-->
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition …Run Code Online (Sandbox Code Playgroud) 我不能在两种转换方法之间进行选择.从枚举转换为int的最佳实践是什么?
1:
public static int EnumToInt(Enum enumValue)
{
return Convert.ToInt32(enumValue);
}
Run Code Online (Sandbox Code Playgroud)
2:
public static int EnumToInt(Enum enumValue)
{
return (int)(ValueType)enumValue;
}
Run Code Online (Sandbox Code Playgroud) c# ×9
.net ×2
.net-3.0 ×1
.net-4.0 ×1
data-binding ×1
enums ×1
ienumerable ×1
linq ×1
resources ×1
unicode ×1
wcf-security ×1
wpf ×1
xaml ×1