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();
Ïà¹ØÎĵµ£º
ÒýÓõØÖ·:http://www.cnblogs.com/heyaowen163/articles/1177909.html
C#¹Ø¼ü×ÖµÄÓ÷¨²»µ¥Ö»ÓÐÒ»ÖÖ·½·¨µÄ¡£ÏÖÔÚÎÒ×ܽáÁËÒ»ÏÂUsingºÍNewµÄÓ÷¨£¬Ë³±ã¹®¹ÌÏÂ×Ô¼ºµÄ֪ʶ¡£
Using
£¨1£©ÒýÓÃÃüÃû¿Õ¼ä
using× ......
(1)stringÊÇÒýÓÃÀàÐÍ£º
stringÊÇÒýÓÃÀàÐÍ£¬Õâ¾ÍÊÇ˵stringÔÚ¶ÑÉϱ£´æÊý¾Ý£¬¶øÔÚÕ»Öд洢µÄÊǶÔÏóµØÖ·£¬ÔÚÀí½âstringÀàÐÍÌØÐÔʱÊ×ÏÈÐèÒª¼ÇסÕâµã¡£Ö»²»¹ýÓëÆäËüһЩÒýÓÃÀàÐÍÏà±È£¬ËüÓÖÓÐһЩ±È½ÏÌØÊâµÄÌØÐÔ£¬±ÈÈçÏÂÃæµÄÕâЩ£º
(2)stringÊDz»¿É±äµÄ(immutable)£º
stringµÄÕâÒ»ÌØÐÔÊÇÖ¸£¬¶ÔÓÚÒÑÓеÄÒ»¸östring¶ÔÏ󣬵±ÄãÐÞ¸ ......
ÀûÓÃWM_COPYDATAÔÚÓ¦ÓóÌÐò¼ä´«µÝÊý¾ÝºÜ¼òµ¥,¿ªÏúҲС
Ò»¡¢´«µÝÊý¾Ý²¿·Ö
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace ThreeTorches
{
public struct Copydatastru ......
ºÍÆäËûÓïÑÔÒ»Ñù£¬C#ʵÏÖÎļþ¹ØÁªÍ¬ÑùÐèÒªÖ±½Ó²Ù×÷×¢²á±í£¬¼´°´¹æÔò·Ö±ðÉèÖÃÎļþÀ©Õ¹Ãû£¬ÎĵµÀàÐÍ˵Ã÷£¬ÓѺÃÃû³Æ£¬Í¼±ê£¬µ÷Ó÷½·¨µÈ¼üÖµ¼´¿É£¬ÍøÉÏËæ±ã²é²é¾Í¿ÉÒÔд³öÒÔϵĴúÂë¡£ using Microsoft.Win32; RegistryKey key = Registry.ClassesRoot.OpenSubKey(".jb");
if (key == null)
{
......