小编Sle*_*idi的帖子

序列与身份

SQL Server 2012 Sequence作为新功能引入,与Oracle和Postgres相同.哪个序列优于身份?为什么我们需要序列?

sql t-sql sql-server sql-server-2012

78
推荐指数
4
解决办法
5万
查看次数

为什么在WCF中不允许方法重载?

假设这是一个 ServiceContract

[ServiceContract]
public interface MyService
{
    [OperationContract]
    int Sum(int x, int y);

    [OperationContract]
    int Sum(double x, double y);

}
Run Code Online (Sandbox Code Playgroud)

在C#中允许方法重载,但WCF不允许您重载operation contracts 托管程序将抛出一段InvalidOperationException时间托管

.net c# wcf overloading

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

Java对象序列化和继承

假设你有这两个类,Foo和Bar,其中Bar扩展了Foo并实现了它们 Serializable

class Foo {

public String name;

public Foo() {
    this.name = "Default";
}

public Foo(String name) {
    this.name = name;
}
}

class Bar extends Foo implements java.io.Serializable {

public int id;

public Bar(String name, int id) {
    super(name);
    this.id = id;
}
}
Run Code Online (Sandbox Code Playgroud)

请注意,Foo没有实现Serializable.那么当条形序列化时会发生什么?

    public static void main(String[] args) throws Exception {

    FileOutputStream fStream=new FileOutputStream("objects.dat");
    ObjectOutputStream oStream=new ObjectOutputStream(fStream);
    Bar bar=new Bar("myName",21);
    oStream.writeObject(bar);

    FileInputStream ifstream = new FileInputStream("objects.dat");
    ObjectInputStream istream = new ObjectInputStream(ifstream);
    Bar bar1 = …
Run Code Online (Sandbox Code Playgroud)

java inheritance serialization object-serialization

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

任务和异常沉默

为什么在任务中抛出的异常是静默异常,你永远不知道是否抛出了某个异常

try
{

 Task task = new Task(
  () => {
          throw null;
        }
        );
  task.Start();
 }
 catch
 {
  Console.WriteLine("Exception");
 }  
Run Code Online (Sandbox Code Playgroud)

程序在完全沉默中成功运行!线程的行为是不同的

try
{

 Thread thread = new Thread(
  () => {
          throw null;
        }
        );
  thread .Start();
 }
 catch
 {
  Console.WriteLine("Exception");
 }
Run Code Online (Sandbox Code Playgroud)

在这种情况下,将抛出空指针异常.有什么不同?

c# multithreading exception-handling task

18
推荐指数
2
解决办法
5289
查看次数

为什么java中没有sizeof

出于什么设计原因,java中没有sizeof运算符?知道它在c ++和c#中非常有用,如果需要你如何获得某种类型的大小?

java sizeof operator-keyword

13
推荐指数
2
解决办法
1775
查看次数

方法重载.它是如何工作的?

假设我有这两个重载函数.

public static void Main(string[]args)
{
     int x=3;
     fn(x); 
}

static void fn(double x)
{ 
    Console.WriteLine("Double");
}

static void fn(float x)
{
    Console.WriteLine("Float");
}
Run Code Online (Sandbox Code Playgroud)

为什么编译器会选择float函数?

c# overloading

11
推荐指数
2
解决办法
690
查看次数

struct和class中使用的泛型

假设我们有以下struct使用泛型的定义:

public struct Foo<T>
{
    public T First; 
    public T Second;

    public Foo(T first)
    {
        this.First = first;
    }

}
Run Code Online (Sandbox Code Playgroud)

编译说

在将控制权返回给调用者之前,必须完全分配'Foo.Second'

但是,如果Foo是一个类,那么它会成功编译.

public class Foo<T>
{
    public T First; 
    public T Second;

    public Foo(T first)
    {
        this.First = first;
    }

}
Run Code Online (Sandbox Code Playgroud)

为什么?为什么编译器对它们的区别对待?此外,如果在第一个中没有定义构造函数,Foo那么它将编译.为什么会这样?

c# generics struct class

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

为什么在finally块中不允许等待?

为什么await不允许一个finally块?

public async void Fn()
{
    try
    {
    }
    finally
    {
        await Task.Delay(4000);
    }
}
Run Code Online (Sandbox Code Playgroud)

知道可以Awaiter手动获取

public void Fn()
{
    try
    {
    }
    finally
    {
        var awaiter = Task.Delay(4000).GetAwaiter();
     }
}
Run Code Online (Sandbox Code Playgroud)

c# async-await c#-5.0

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

虚拟属性和延迟加载

根据定义,虚拟属性或方法是要被覆盖的子类可见的方法.但是,例如NHibernate使用虚拟属性来确保延迟加载.

我的问题不是关于NHibernate,而是如何使用虚拟属性来实现延迟加载?是否有任何关于我不知道的虚拟属性的隐藏行为?

c# virtual lazy-loading properties

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

在try块中抛出异常有什么问题吗?

try-catch如下编码块是一种很好的设计实践吗?也就是说,throw在try块中使用a 然后在catch块中捕获它.

try
{
  if (someCondition){

      throw new Exception("Go the the associated catch block!");

     }
}

catch(Exception ex)
{
      logError("I was thrown in the try block above");
}
Run Code Online (Sandbox Code Playgroud)

c#

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