[.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=1, 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(2008, 12, 31, 23, 59, 50); DateTime midnight = new DateTime(2009, 1, 1, 0, 0, 0); Console.WriteLine("Time... "); while (now < midnight) { Console.WriteLine("Now: " + now); System.Threading.Thread.Sleep(1000); now = now.AddSeconds(1); } 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 = 2; Test<int> test = new Test<int>(obj); Test<string> test1 = new Test<string>(obj.ToString()); Console.WriteLine((test.obj+2)+","+(test1.obj+2)); 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 =7777}, new Customer {ID ="D",City ="New York",Country ="USA", Region ="North America",Sales =9999}, new Customer {ID ="E",City ="BeiJing",Country ="China", Region ="Asia",Sales =8888}, new Customer {ID ="F",City ="New York",Country ="USA", Region ="North America",Sales =9999} }; 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>
==============================================================================================