IIS Expression错误:Could not load file or assembly … An attempt was made to load a program with an incorrect format

在Visual Studio 2015中跑IIS Express遇到错误:Could not load file or assembly … An attempt was made to load a program with an incorrect format.
尝试修改:(右键)Project-> Properties -> Build,将Build中的Platform target修改为Any CPU,无效。

解决方法如下:

Tools->Options->Projects and Solutions -> Web Projects,
将“Use the 64 bit version of IIS Express for web sites and projects”选上。

然后重新build solution,F5开始debug就可以了。

by Code问答

C#中的typeof, GetType和is的用法比较

在C#中,虽然typeof,GetType和is虽然都用于类型的判断,但是各有区别。

typeof关键字

typeof为C#的关键字,typeof的参数为类型名称,返回一个System.Type的对象,它的返回值在编译是确定。

GetType()方法

GetType为C#的Object类提供的方法,GetType方法在运行时返回一个对象的类型。

is关键字

is是C#中的运算符关键字(operator keywords),is表达式返回的是bool类型,表示一个对象是否为某个类型的实例。

比较代码

具体用法的代码如下:

class Animal { } 
class Dog : Animal { }

void PrintTypes(Animal a) { 
    print(a.GetType() == typeof(Animal)) // false 
    print(a is Animal)                   // true 
    print(a.GetType() == typeof(Dog))    // true
}

Dog spot = new Dog(); 
PrintTypes(spot);

is关键字用法补充

class Animal { } 
class Dog : Animal { }

Animal just_a_animal = new Animal();
var check1 just_a_animal is Animal(); // true
var check2 just_a_animal is Dog(); // false

Animal probably_a_dog = new Dog();
var check3 = probably_a_dog is Dog; // true
var check4 = probably_a_dog is Animal; // true

Dog definitely_a_dog = new Dog();
var check5 = definitely_a_dog is Animal; // true
var check6 = definitely_a_dog is Dog; // true