int i = 12;
double d = i;
就类似这样,低精度转高精度不需要强制转换,可以隐式转换
子类转基类也不需要强制转换
反过来就不行了
double d = i;
就类似这样,低精度转高精度不需要强制转换,可以隐式转换
子类转基类也不需要强制转换
反过来就不行了
解决方案 »
- 怎样将word中的“首行缩进”功能转换为html中的“首行缩进”功能
- 这句话有什么作用?
- 请教高手,c#开发BHO如何改写网页内容?
- 请问如何实现像VS中属性选项卡那种自由左右托动及可以自动隐藏到左边的功能呢?
- Lambda表达式的问题
- C# winform引用的dll可以不放在exe同目录吗?
- 请教!!!!!!!!!!!!急求C#入门至精通教程,望推荐好书(可加更多分)
- 为什么reportviewer无法使用?
- startindex 不能小于 0
- list<string> 如何查询次数?
- winform程序 xp、win7显示正常 win8显示不正常
- 请问在图片控件上增删标志图应该怎么实现?
"向上转型"是什么?请说英文。这么写还是有区别的:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;namespace ConsoleApplication1
{
class Animal
{
public void A() { Console.WriteLine("A"); }
} class Dog : Animal
{
public new void A() { Console.WriteLine("D"); }
} class Program
{
static void Main(string[] args)
{
Dog dog = new Dog();
dog.A();
((Animal)dog).A();
}
}
}
{
static void Main(string[] args)
{
Dog dog = new Dog();
dog.A();
((Animal)dog).A();
}
} dog.A(); //直接使用子类的A方法,子类用一个A方法替换基类的A方法,关键字new
((Animal)dog).A(); //使用父类的A方法
"向上转型"是什么?请说英文。这么写还是有区别的:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;namespace ConsoleApplication1
{
class Animal
{
public void A() { Console.WriteLine("A"); }
} class Dog : Animal
{
public new void A() { Console.WriteLine("D"); }
} class Program
{
static void Main(string[] args)
{
Dog dog = new Dog();
dog.A();
((Animal)dog).A();
}
}
}向上转型:upcasting 所有面向对象语言的基础语法之一,忘了在哪本书上看的了