小编Sar*_*gam的帖子

EventLog.WriteEntry和EventLog.WriteEvent方法之间的区别

我尝试使用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()方法的重载来完成,而不是引入一个新的方法?

.net .net-2.0

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

StringBuilder与StringWriter/StringReader

我最近读过它StringWriterStringReader用于写作和阅读StringBuilder.

好吧,当我使用StringBuilderObject时,它看起来是一个自给自足的类.

我们的阅读和写作的各种方式StringBuilder,使用 StringBuilder.Append(),Insert(),Replace(),Remove()等...

  1. 什么是可能的使用StringWriterStringReader,它StringBuilder本身不能完成?
  2. 它们的实际用途是什么?
  3. 可能的原因是它们没有Stream作为输入(因为任何其他编写器和读取器都将流作为Constructor参数进行操作)但是StringBuilder

.net c# stringbuilder stringreader c#-3.0

31
推荐指数
2
解决办法
2万
查看次数

System.ValueType了解

我试图创建一个ValueType.

我知道创建一个结构对我有帮助.

我还尝试从System.ValueType派生一个类型,它是一个抽象类.

但我得到一个编译器错误消息" ..无法从特殊类System.ValueType派生 "

当我看到ValueType的元数据时,它看起来是一个常规的抽象类.

  1. 是什么让它与众不同?

  2. 是C#compilor感觉它特别吗?

  3. 如果是这样,它是否建议作为编译器设计的规则?我的意思是它是公共语言规范的一部分吗?

c# .net-2.0

31
推荐指数
2
解决办法
2万
查看次数

消息中至少有一个安全令牌无法验证

服务器配置:

<?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)

security wcf web-services certificate wshttpbinding

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

什么是URL中的ww2/www2

我最近注意到一些网站的网址有ww2或www2.这些是什么?最近出现了什么新东西?是否有任何链接可以获得更多相关信息?

url

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

System.Comparison <T>理解

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>.它是如何工作的?

.net

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

多线程中的死锁

我试图创建一个死锁的例子.我尝试了以下代码.但它并没有造成僵局,而是像魅力一样.帮助我理解为什么它没有造成死锁.此代码中的哪些更改会造成死锁?

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)

c# multithreading

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

为什么我们递归地实现接口?

我知道任何Collection(这里我说的是常规非泛型)应该已经实现了ICollection,IEnumerable和IList包含常规对象集合或IDictionary,如果是字典.

[尽管如此,我问的问题并非特定于收藏]

IList派生自ICollection和IEnumerable

ICollection派生自IEnumerable

是不是只使集合(例如ArrayList)实现IList?

在对象浏览器中,它显示集合类(例如ArrayList)正在实现IList,ICollection和IEnumerator.

我知道即使我们指定所有三个集合,.Net也只接受一次定义.

但我的问题是,

  1. 是否有任何最佳实践或建议指导我们为集合类指定所有三个接口(或者与此类似的任何类)?

  2. 或者只是对象浏览器的属性将其显示为3个单独的实现?[刚查过,发现它不是Object浏览器的属性.对象浏览器只显示类定义中指定的接口]

.net collections

6
推荐指数
2
解决办法
320
查看次数

枚举Int32类型的成员

可能重复:
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#不编译代码的原因是什么?

c#

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

删除SSIS数据流中的重复项

我正在处理SSIS数据流任务.

源表来自旧数据库,它是非规范化的.

目标表已规范化.

SSIS失败,因为由于重复(主键列中的重复项)而无法进行数据传输.

如果SSIS可以检查目的地是否有当前记录(通过检查密钥),如果它存在,那么它可以忽略推送它.然后它可以继续下一条记录.

有办法处理这种情况吗?

ssis

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