[.net 面向对象编程基础] (23) 结束语
[.net 面向对象编程基础] (23) 结束语
这个系列的文章终于写完了,用了半个多月的时间,没有令我的粉丝们失望。我的感觉就是一个字累,两个字好累,三个字非常累。小伙伴们看我每篇博客的时间就知道了,有多少个凌晨2、3点才完成的。其实在日常工作中用起来虽然比较容易,但要是真正的写出来,又要写的让初学者能看明白,真不是一件轻松的事情,其中里面有好多示例都要考虑如何写才能通俗易懂。
写这个系列的文章,有很多也是参考了博客园和网上的文章,没有一一列举出原作者和URL,在此表示感谢和歉意。但是我可以保证,我没有纯复制粘贴过一篇文章,每写一节我都融入了自己的理解,耐心的写了每一个示例,力求不误导初学者。每一个示例都可以编译通过,正常运行。我想编程者都要有一颗OPEN的心。这样才能自己进步,也能让更多的人进步。
当有很多小伙伴还在拿着一个月3~5K的工资混日子的时候,有些人已经年薪30~50W(当然我并没有这么碉)。想一下,别人付出了多少,当你还在群里问别人类型怎么转换的时候,有些人已经在在研究架构和设计模式;当你天天抱怨程序员就是民工的时候,有些程序员开着豪车、住着别墅,身边带着N+1个妹纸(当然这些也不是我,我还在路上)。 我就想说不论你是什么职位,做什么工作,都有TOP。
这系列文章只是一个.Net面向对象的入门或者说是一个基础的文章,当然你弄懂了这些,才是打开设计模式和架构设计的钥匙。学会了这些,你可以去理抬头挺胸的去面试任何一家.net工程师。如果你学会了还没面试上,那只能说是Interviewer有眼无珠(如果还失败,那你来我们单位,^_^)当然如果有时间,我会继续写一些系列文章。
最后我发一下我的博客签名“No pains,No gains.”没有付出就没有收获,祝小伙伴们都成为大牛!
--------------------------------------------------------------------------------------
为了不使这篇文件没具体内容,我把我最近招聘试题附上,有了上面的知识,百分百通关!
--------------------------------------------------------------------------------------
C# 高级工程师
(编号:201505060129)
要求:a.判断对错,如错误,请说明错误原因;
b.请将答案填写在答题卡上;
c.要求30分钟内完成。
1.有以下类AppleTree和Apple、Tree是继承关系,下面写法是否正确
public class Tree{ }
public class Apple{ }
public class AppleTree:Tree,Apple{}
2.有以下类Tree 和 AppleTree, AppleTree 继承于Tree, 并调用,以下写法是否正确
public class Tree
{
public abstract Color LeafColor { get; }
}
public class AppleTree:Tree
{
public override Color LeafColor
{
get
{
return Color.Green;
}
}
}
3. 有以下接口Tree , AppleTree 继承于Tree并实现接口成员方法,以下写法是否正确
public interface Tree
{
void Leaf();
void Flower();
}
public class AppleTree : Tree
{
void Leaf()
{
Console.WriteLine("The color is green !");
}
}
4.有类FujiAppleTree和 接口 Tree 、 AppleTree 以下写法是否正确
public class Tree
{
Color Leaf { get; }
}
public interface AppleTree : Tree
{
new Color Leaf { get; }
}
public class FujiAppleTree:AppleTree
{
public Color Leaf { get { return Color.Green; } }
}
5.以下关于TreeType枚举定义,写法是否正确
public enum TreeType:uint
{
Apple,
Maple=,
Ginkgo
}
6.以下获通过使用委托调用方法,写法是否正确
static void Main(string[] args)
{
Console.WriteLine(GetTreeColor(TreeType.Ginkgo).Name.ToString());
}
public enum TreeType:uint { Apple,Maple, Ginkgo }
public delegate Color GetTreeColor(TreeType treeType);
private abstract class Tree
{
public static Color GetTreeColor(TreeType treeType)
{
switch (treeType)
{
case TreeType.Apple:
return Color.Green;
case TreeType.Maple:
return Color.Red;
case TreeType.Ginkgo:
return Color.Yellow;
default:
return Color.Green;
}
}
}
7.以下代码实现一个自定义事件,事件触发过程为:午夜到来-》有小偷进入-》主人呼叫狗 -》 赶走小偷,其中Dog为事件接收类,Host为事件发送类,根据以下代码判断过程描述是否正确
class Program
{
static void Main(string[] args)
{
Dog dog = new Dog();
Host host = new Host(dog);
DateTime now = new DateTime(, , , , , );
DateTime midnight = new DateTime(, , , , , );
Console.WriteLine("Time... ");
while (now < midnight)
{
Console.WriteLine("Now: " + now);
System.Threading.Thread.Sleep();
now = now.AddSeconds();
}
Console.WriteLine("\n Thief: " + now);
Console.WriteLine("The thief came.... ");
dog.OnAlarm();
}
}
class Dog
{
public delegate void AlarmEventHandler(object sender, EventArgs e);
public event AlarmEventHandler Alarm;
public void OnAlarm()
{
if (this.Alarm != null)
{
Console.WriteLine("\Wang wang!!");
this.Alarm(this, new EventArgs());
}
}
}
class Host
{
void HostHandleAlarm(object sender, EventArgs e)
{
Console.WriteLine("Have caught the thief");
}
public Host(Dog dog)
{
dog.Alarm += new Dog.AlarmEventHandler(HostHandleAlarm);
}
}
8. 以下代码输出结果为22,22,是否正确
static void Main(string[] args)
{
int obj = ;
Test<int> test = new Test<int>(obj);
Test<string> test1 = new Test<string>(obj.ToString());
Console.WriteLine((test.obj+)+","+(test1.obj+));
Console.Read();
}
class Test<T>
{
public T obj;
public Test(T obj)
{
this.obj = obj;
}
}
9. 以下代码输出结果为“39996:USA;16665:China;”是否正确
static void Main(string[] args)
{
List<Customer> customers = new List<Customer> {
new Customer {ID ="A",City ="New York",Country ="USA",Region ="North
America",Sales =9999},
new Customer {ID ="B",City ="New York",Country ="USA",Region ="North
America",Sales =9999},
new Customer {ID ="C",City ="XiAn",Country ="China",Region ="Asia",
Sales =},
new Customer {ID ="D",City ="New York",Country ="USA",
Region ="North America",Sales =},
new Customer {ID ="E",City ="BeiJing",Country ="China",
Region ="Asia",Sales =},
new Customer {ID ="F",City ="New York",Country ="USA",
Region ="North America",Sales =}
};
var orderedResults = from cg in (from c in customers
group c by c.Regioninto cg
select new { TotalSales = cg.Sum(c => c.Sales), Region = cg.Key })
orderby cg.TotalSales descending
select cg; string result="";
foreach (var item in orderedResults)
result += item.TotalSales + ":" + item.Region+";";
Console.WriteLine(result);
Console.ReadLine();
}
}
10. 以下程序调用部分执行后,通过反射执行方式是否正确
//调用部分
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string SpaceName = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Namespace;
string ClassType = Console.ReadLine();
object obj = Assembly.GetExecutingAssembly().CreateInstance(SpaceName+".OranageTree", false);
object obj2 = Type.GetType(SpaceName + ".OranageTree").GetMethod(ClassType + "Color").Invoke(obj, null);
Console.ReadLine();
}
}
}
//实现部分
namespace ConsoleApplication2
{
public class OranageTree
{
public static void FruitColor()
{
Console.WriteLine("Oranage Fruit Color:Oranage");
} public static void LeafColor()
{
Console.WriteLine("Oranage Leaf Color:Green");
}
}
}
C# 高级工程师 答题卡
|
姓名 |
|
应聘职位 |
|
序号 |
正确(Y)错误(N) |
原因(如错误,请在此说明错误原因) |
|
1 |
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
==============================================================================================
<如果对你有帮助,记得点一下推荐哦,如有有不明白或错误之处,请多交流>
如果本系列文章都掌握了,可以看一下 《.NET 面向对象程序设计进阶》
<转载声明:技术需要共享精神,欢迎转载本博客中的文章,但请注明版权及URL>
.NET 技术交流群:467189533 
==============================================================================================
[.net 面向对象编程基础] (23) 结束语的更多相关文章
- [.net 面向对象编程基础] (1) 开篇
[.net 面向对象编程基础] (1)开篇 使用.net进行面向对象编程也有好长一段时间了,整天都忙于赶项目,完成项目任务之中.最近偶有闲暇,看了项目组中的同学写的代码,感慨颇深.感觉除了定义个类,就 ...
- [.net 面向对象编程基础] (4) 基础中的基础——数据类型转换
[.net面向对象编程基础] (4)基础中的基础——数据类型转换 1.为什么要进行数据转换? 首先,为什么要进行数据转换,拿值类型例子说明一下, 比如:我们要把23角零钱,换成2.30元,就需要把整形 ...
- [.net 面向对象编程基础] (18) 泛型
[.net 面向对象编程基础] (18) 泛型 上一节我们说到了两种数据类型数组和集合,数组是指包含同一类型的多个元素,集合是指.net中提供数据存储和检索的专用类. 数组使用前需要先指定大小,并且检 ...
- [.net 面向对象编程基础] (20) LINQ使用
[.net 面向对象编程基础] (20) LINQ使用 通过上节LINQ的基础知识的学习,我们可以开始使用LINQ来进行内存数据的查询了,我们上节说了LINQ的定义为:Language Integr ...
- Java面向对象编程基础
一.Java面向对象编程基础 1.什么是对象?Object 什么都是对象! 只要是客观存在的具体事物,都是对象(汽车.小强.事件.任务.按钮.字体) 2.为什么需要面向对象? 面向对象能够像分析现实生 ...
- Python学习-第三天-面向对象编程基础
Python学习-第三天-面向对象编程基础 类和对象 简单的说,类是对象的蓝图和模板,而对象是类的实例.这个解释虽然有点像用概念在解释概念,但是从这句话我们至少可以看出,类是抽象的概念,而对象是具体的 ...
- 第二章 Matlab面向对象编程基础
DeepLab是一款基于Matlab面向对象编程的深度学习工具箱,所以了解Matlab面向对象编程的特点是必要的.笔者在做Matlab面向对象编程的时候发现无论是互联网上还是书店里卖的各式Matlab ...
- [Java入门笔记] 面向对象编程基础(二):方法详解
什么是方法? 简介 在上一篇的blog中,我们知道了方法是类中的一个组成部分,是类或对象的行为特征的抽象. 无论是从语法和功能上来看,方法都有点类似与函数.但是,方法与传统的函数还是有着不同之处: 在 ...
- [.net 面向对象编程基础] (2) 关于面向对象编程
[.net 面向对象编程基础] (2) 关于面向对象编程 首先是,面向对象编程英文 Object-Oriented Programming 简称 OOP 通俗来说,就是 针对对象编程的意思 那么问 ...
随机推荐
- rem介绍
手机端开发,一般以320px宽为最低标题.市场上的手机,大多数是360px宽. 20px=1rem是最容易换算的,基本上可以口算,除以2并缩小十倍.1px/20=0.05rem.两位小数就可以除尽了. ...
- C++中关于文件的读写
在C++的学习过程中,我们时常要用到对文件的操作,下面我们讲一下文件的读写. 首先,读.也就是把已有的文件读到控制台上,那么如何操作呢?首先要将文件操作的输入输出流包含进去. <fstream& ...
- win64
修改IIS应用程序池,启用支持32位 未能写入输出文件“c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary AS
- Linux中的工作管理(Job Control )
以前使用Linux老是会不小心按下Ctrl + z,然后就出现看不懂的情况,以为程序突然就没了,今天专门研究了下Linux下的几个快捷键和工作管理. 其中找到一篇很不错的文章,大部分是里面转载的. 原 ...
- EasyUI DataGrid getChecked/getSelections 获取不到数据
今天使用getChecked获取选择的行,结果总是获取一行数据,于是换用getSelections,结果还是一样,想起之前做的项目,把idField换了下,之后getChecked/getSelect ...
- Groovy 处理 XML
1. Parsing XML 1.1. XmlParser and XmlSlurper The most commonly used approach for parsing XML with Gr ...
- 自己对Extjs的Xtemplate的忽略
之前学习extjs Xtmeplate受一些书籍的误导,说Xtemplate不支持else ,今天仔细看了官网的示例,才恍然大悟,卧槽!不仅支持if-elseif-else结构 连switch都能够支 ...
- How to copy remote computer files quickly to local computer
if we want copy file from VM(Remote VM) to local computer. Always can not easy copy file so easy. no ...
- MyBatis使用动态SQL标签的小陷阱
现在MyBatis越来越受大家的喜爱了,它的优势大家都知道,我就不多说了,直接说重点. MyBatis中提供动态SQL功能,我们可以使用<if><when><where& ...
- ARP包分析(wireshark)
ARP数据报格式(42字节) 这是用wireshark抓到的一个ARP包,42个字节. 这个ARP包的 以太网首部(14字节): 字段 长度(Byte) ...