Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

c# virtualÐ麯ÊýµÄnew¡¢overrideʵÏÖ

c#ÖлùÀࣨ¸¸ÀࣩÖеÄij·½·¨ÈôÏëÔÚÅÉÉúÀࣨ×ÓÀࣩÖб»ÖØÐ´£¨override£©£¬±ØÐ뽫»ùÀàÖеķ½·¨¶¨ÒåΪvirtual£¬¼´Ð麯Êý¡£
ÈôÅÉÉúÀཫ·½·¨ÐÞÊÎΪnew£¬¼´ÓÐÒâÒþ²Ø»ùÀàÖеķ½·¨¡£
ÏÂÃæ¿´Ò»×é´úÂ룺
public class Father
{
public void hand()
{
Console.WriteLine("Father.hand");
}
}
public class Son : Father
{
public void hand()
{
Console.WriteLine("Son.hand");
}
static void Main(string[] args)
{
Father son = new Son();
son.hand();
Console.ReadLine();
}
}

Êä³ö£ºFather.hand
¾¯¸æ£º“Son.hand()”½«Òþ²Ø¼Ì³ÐµÄ³ÉÔ±“Father.hand()”¡£ÈôҪʹµ±Ç°³ÉÔ±ÖØÐ´¸ÃʵÏÖ£¬ÇëÌí¼Ó¹Ø¼ü×Ö override¡£·ñÔò£¬Ìí¼Ó¹Ø¼ü×Ö new¡£
public class Father
{
public void hand()
{
Console.WriteLine("Father.hand");
}
}
public class Son : Father
{
public override void hand()
{
Console.WriteLine("Son.hand");
}
static void Main(string[] args)
{
Father son = new Son();
son.hand();
Console.ReadLine();
}
}
 
±àÒë´íÎ󣺓Son.hand()”: ¼Ì³Ð³ÉÔ±“Father.hand()”δ±»±ê¼ÇΪ virtual¡¢abstract »ò override£¬ÎÞ·¨½øÐÐÖØÐ´¡£
public class Father
{
public virtual void hand()
{
Console.WriteLine("Father.hand");
}
}
public class Son : Father
{
public override void hand()
{
Console.WriteLine("Son.hand");
}
static void Main(string[] args)
{
Father son = new Son();
son.hand();
Console.ReadLine();
}
}

Êä³ö£ºSon.hand
ÎÞ¾¯¸æ¡£
public class Father
{
public void hand()
{
Console.WriteLine("Father.hand");
}
}
public class Son : Father
{
public new void hand()
{
Console.WriteLine("Son.hand");
}
static void Main(string[] args)
{
Father son = new Son();
son.hand();


Ïà¹ØÎĵµ£º

C#ÓïÑԹ淶

1. ÃüÃû¹æ·¶
a)    Àà
¡¾¹æÔò1-1¡¿Ê¹ÓÃPascal¹æÔòÃüÃûÀàÃû£¬¼´Ê××ÖĸҪ´óд¡£
¡¾¹æÔò1-2¡¿Ê¹ÓÃÄܹ»·´Ó³À๦ÄܵÄÃû´Ê»òÃû´Ê¶ÌÓïÃüÃûÀà¡£
¡¾¹æÔò1-3¡¿²»ÒªÊ¹ÓÓI”¡¢“C”¡¢“_”µÈÌØ¶¨º¬Òåǰ׺¡£
¡¾¹æÔò1-4¡¿×Ô¶¨ÒåÒì³£ÀàÓ¦ÒÔException½áβ¡£
¡¾¹æÔò1-5¡¿ÎļþÃûÒªÄÜ·´Ó ......

C# תÒåÐòÁÐ Unicode ×Ö·û±àÂë

תÒåÐòÁР       ×Ö·ûÃû³Æ        Unicode ±àÂë
\'        µ¥ÒýºÅ        0x0027
\"        Ë«Òýº ......

c# Àà¿â

[SerializableAttribute]
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDual)]
public class Object
1 public virtual bool Equels (Object)
2 public static bool static Equels (Object,Object)
ĬÈÏʵÏÖΪ¶ÔÒýÓÃÀàÐÍʹÓÃÒýÓÃÏàµÈ£¬¶ÔÖµÀàÐÍʹÓöþ½øÖư´Î»ÏàµÈ¡£ÒýÓÃÏàµÈÐÔÊÇÖ¸½ø ......

C# ¹Ø¼ü×ÖexternÓ÷¨

ÐÞÊηûÓÃÓÚÉùÃ÷ÔÚÍⲿʵÏֵķ½·¨¡£extern ÐÞÊηûµÄ³£¼ûÓ÷¨ÊÇÔÚʹÓà Interop ·þÎñµ÷Èë·Ç
ÍйܴúÂëʱÓë DllImport ÊôÐÔÒ»ÆðʹÓã»ÔÚÕâÖÖÇé¿öÏ£¬¸Ã·½·¨»¹±ØÐëÉùÃ÷Ϊ static£¬ÈçÏÂÃæµÄʾÀýËùʾ£º[DllImport("avifil32.dll")]
private static extern void AVIFileInit();
×¢Òâ
extern ¹Ø¼ü×Ö»¹¿ÉÒÔ¶¨ÒåÍⲿ³ÌÐò¼¯±ðÃû£¬Ê¹ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ