我尝试使用WriteEntry
和类的WriteEvent
方法EventLog
.
EventLog.WriteEntry("Saravanan", "Application logs an entry",
EventLogEntryType.Information, 2, 3);
EventLog.WriteEvent("Saravanan", new EventInstance(2, 3),
"Application logs an event");
Run Code Online (Sandbox Code Playgroud)
两者都输出相同的结果.
这些方法的使用有什么不同吗?
如果只有微小的差异,为什么不通过任何一个WriteEvent()
或WriteEntry()
方法的重载来完成,而不是引入一个新的方法?
我最近读过它StringWriter
并StringReader
用于写作和阅读StringBuilder
.
好吧,当我使用StringBuilder
Object时,它看起来是一个自给自足的类.
我们的阅读和写作的各种方式StringBuilder
,使用
StringBuilder.Append()
,Insert()
,Replace()
,Remove()
等...
StringWriter
和StringReader
,它StringBuilder
本身不能完成?Stream
作为输入(因为任何其他编写器和读取器都将流作为Constructor参数进行操作)但是StringBuilder
?我试图创建一个ValueType.
我知道创建一个结构对我有帮助.
我还尝试从System.ValueType派生一个类型,它是一个抽象类.
但我得到一个编译器错误消息" ..无法从特殊类System.ValueType派生 "
当我看到ValueType的元数据时,它看起来是一个常规的抽象类.
是什么让它与众不同?
是C#compilor感觉它特别吗?
如果是这样,它是否建议作为编译器设计的规则?我的意思是它是公共语言规范的一部分吗?
服务器配置:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceCredentialsBehavior">
<serviceCredentials>
<serviceCertificate findValue="cn=cool" storeName="TrustedPeople" storeLocation="CurrentUser" />
</serviceCredentials>
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceCredentialsBehavior" name="Service">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="MessageAndUserName" name="SecuredByTransportEndpoint" contract="IService"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="MessageAndUserName">
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client/>
</system.serviceModel>
<system.web>
<compilation debug="true"/>
</system.web>
Run Code Online (Sandbox Code Playgroud)
我的客户端配置:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="LocalCertValidation">
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="PeerTrust" trustedStoreLocation="CurrentUser" />
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService" >
<security mode="Message"> …
Run Code Online (Sandbox Code Playgroud) List<T>.Sort()
方法有3个重载.
其中之一如下
System.Collections.Generic.List<T>.Sort(System.Comparison<T>)
Run Code Online (Sandbox Code Playgroud)
在看到时Comparison<T>
,我认为它应该是一个派生自Comparison<T>
类的类.(对参数的通常解释)
但是下面的工作非常好,据说使用了上面的重载.
public static void Main(string[] args)
{
List<Int32> collection = new List<Int32>();
collection.Add(20);
collection.Add(270);
collection.Add(30);
collection.Add(90);
collection.Add(40);
collection.Add(18);
collection.Add(100);
collection.Sort(MyComparer.CompareWithCase);
foreach (Int32 s in collection)
Console.WriteLine(s);
}
public static int CompareWithCase(int i1, int i2)
{
return i1.ToString().CompareTo(i2.ToString());
}
Run Code Online (Sandbox Code Playgroud)
我确实给了代理一个静态方法代替Comparison<T>
.它是如何工作的?
我试图创建一个死锁的例子.我尝试了以下代码.但它并没有造成僵局,而是像魅力一样.帮助我理解为什么它没有造成死锁.此代码中的哪些更改会造成死锁?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ReferenceTypes
{
class DeadLockExample
{
static int a;
static int b;
public static void Main(string[] args)
{
DeadLockExample.a = 20;
DeadLockExample.b = 30;
DeadLockExample d = new DeadLockExample();
Thread tA = new Thread(new ThreadStart(d.MethodA));
Thread tB = new Thread(new ThreadStart(d.MethodB));
tA.Start();
tB.Start();
Console.ReadLine();
}
private void MethodA()
{
lock (this)
{
Console.WriteLine(a);
Thread.Sleep(1000);
Console.WriteLine(b);
}
}
private void MethodB()
{
lock (this)
{
Console.WriteLine(b);
Thread.Sleep(1000);
Console.WriteLine(a);
}
} …
Run Code Online (Sandbox Code Playgroud) 我知道任何Collection(这里我说的是常规非泛型)应该已经实现了ICollection,IEnumerable和IList包含常规对象集合或IDictionary,如果是字典.
[尽管如此,我问的问题并非特定于收藏]
IList派生自ICollection和IEnumerable
ICollection派生自IEnumerable
是不是只使集合(例如ArrayList)实现IList?
在对象浏览器中,它显示集合类(例如ArrayList)正在实现IList,ICollection和IEnumerator.
我知道即使我们指定所有三个集合,.Net也只接受一次定义.
但我的问题是,
是否有任何最佳实践或建议指导我们为集合类指定所有三个接口(或者与此类似的任何类)?
或者只是对象浏览器的属性将其显示为3个单独的实现?[刚查过,发现它不是Object浏览器的属性.对象浏览器只显示类定义中指定的接口]
可能重复:
C#int,Int32和enum
这可能是一个相当基本/简单的问题,我正在通过以下方式创建枚举.
案例1编译完美.但案例2引发了错误.我理解int和Int32在C#中的含义相同.
情况1
[Flags]
public enum MyEnum : int
{
Red = 0x1,
Green = 0x2,
Blue = 0x4
}
Run Code Online (Sandbox Code Playgroud)
案例2
[Flags]
public enum MyEnum : Int32
{
Red = 0x1,
Green = 0x2,
Blue = 0x4
}
Run Code Online (Sandbox Code Playgroud)
这里的区别是什么以及当enum的成员被指定为Int32类型时C#不编译代码的原因是什么?
我正在处理SSIS数据流任务.
源表来自旧数据库,它是非规范化的.
目标表已规范化.
SSIS失败,因为由于重复(主键列中的重复项)而无法进行数据传输.
如果SSIS可以检查目的地是否有当前记录(通过检查密钥),如果它存在,那么它可以忽略推送它.然后它可以继续下一条记录.
有办法处理这种情况吗?
.net ×4
c# ×4
.net-2.0 ×2
c#-3.0 ×1
certificate ×1
collections ×1
security ×1
ssis ×1
stringreader ×1
url ×1
wcf ×1
web-services ×1