SQL Server 2012 Sequence作为新功能引入,与Oracle和Postgres相同.哪个序列优于身份?为什么我们需要序列?
假设这是一个 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时间托管
假设你有这两个类,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) 为什么在任务中抛出的异常是静默异常,你永远不知道是否抛出了某个异常
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)
在这种情况下,将抛出空指针异常.有什么不同?
出于什么设计原因,java中没有sizeof运算符?知道它在c ++和c#中非常有用,如果需要你如何获得某种类型的大小?
假设我有这两个重载函数.
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函数?
假设我们有以下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那么它将编译.为什么会这样?
为什么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) 根据定义,虚拟属性或方法是要被覆盖的子类可见的方法.但是,例如NHibernate使用虚拟属性来确保延迟加载.
我的问题不是关于NHibernate,而是如何使用虚拟属性来实现延迟加载?是否有任何关于我不知道的虚拟属性的隐藏行为?
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# ×7
java ×2
overloading ×2
.net ×1
async-await ×1
c#-5.0 ×1
class ×1
generics ×1
inheritance ×1
lazy-loading ×1
properties ×1
sizeof ×1
sql ×1
sql-server ×1
struct ×1
t-sql ×1
task ×1
virtual ×1
wcf ×1