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();
Ïà¹ØÎĵµ£º
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace PortScanner
{
class Program
{
¡¡//ÒÑɨÃè¶Ë¿ÚÊýÄ¿
¡¡internal static int scannedCount = 0;
¡¡//ÕýÔÚÔËÐеÄÏß³ÌÊýÄ¿
¡¡internal static int ru ......
C:\ProgramFiles\MicrosoftVisual Studio .NET\ FrameworkSDK\Samples\ Technologies\ Interop\PlatformInvoke\ WinAPIs\CSĿ¼ÏÂÓдóÁ¿µÄµ÷ÓÃAPIµÄÀý×Ó¡£
Ò»¡¢µ÷Óøñʽ
using System.Runtime.InteropServices; //ÒýÓôËÃû³Æ¿Õ¼ä£¬¼ò»¯ºóÃæµÄ´úÂë
//ʹÓÃDllImportAttributeÌØÐÔÀ´ÒýÈëapiº¯Êý£¬×¢ÒâÉùÃ÷µÄÊǿշ½·¨£¬¼´·½· ......
C#»Ï߿ؼþµÄÓ¦ÓÃʵÀý½éÉÜ֮ǰÎÒÃÇÒªÃ÷°×ÔÚC#ÖÐûÓлÏߵĿؼþ£¬ÕâÀïдÁËÒ»¸ö£¬´ó¼Ò·ÖÏí¡£¹²ÓÐÁ½¸ö¿Ø¼þ·Ö±ðÊÇ»ºáÏߺͻÊúÏߵ쬹ØÓÚÔõô»Ð±ÏßÓÐÐËȤµÄ¿ÉÒÔ×öÒ»¸ö´ó¼Ò·ÖÏí¡£
C#»Ï߿ؼþÖ®ºáÏß
using System;
using System.Collections;
using System.ComponentModel; ......
C#ÕýÔò±í´ïʽƥÅä×Ö·û´®µÄ·½·¨ÈçÏ£º
1.ʹÓÃC#ÖÐʹÓÃÕýÔò±í´ïʽSystem.Text.RegularExpressionsÃüÃû¿Õ¼ä£»
2.ʹÓÃC#ÖÐʹÓÃÕýÔò±í´ïʽMatches()·½·¨Æ¥Åä×Ö·û´®£¬¸ñʽÈçÏ£º
MatchCollection Matches = Regex.Matches(Str, Pattern, RegexOptions.IgnoreCase | RegexOptions.ExplicitC ......
ºÍÆäËûÓïÑÔÒ»Ñù£¬C#ʵÏÖÎļþ¹ØÁªÍ¬ÑùÐèÒªÖ±½Ó²Ù×÷×¢²á±í£¬¼´°´¹æÔò·Ö±ðÉèÖÃÎļþÀ©Õ¹Ãû£¬ÎĵµÀàÐÍ˵Ã÷£¬ÓѺÃÃû³Æ£¬Í¼±ê£¬µ÷Ó÷½·¨µÈ¼üÖµ¼´¿É£¬ÍøÉÏËæ±ã²é²é¾Í¿ÉÒÔд³öÒÔϵĴúÂë¡£ using Microsoft.Win32; RegistryKey key = Registry.ClassesRoot.OpenSubKey(".jb");
if (key == null)
{
......