ʹÓÃC#¸ñʽ»¯×Ö·û´®£¨×ª×Ô²©¿ÍÔ°£©
1 Ç°ÑÔ
Èç¹ûÄãÊìϤMicrosoft Foundation Classes£¨MFC£©µÄCString£¬Windows Template
Library£¨WTL£©µÄCString»òÕßStandard Template
Library£¨STL£©µÄ×Ö·û´®À࣬ÄÇôÄã¶ÔString.Format·½·¨¿Ï¶¨ºÜÊìϤ¡£ÔÚC#ÖÐÒ²¾³£Ê¹ÓÃÕâ¸ö·½·¨À´¸ñʽ»¯×Ö·û´®£¬±ÈÈçÏÂÃæÕâÑù£º
int x = 16;
decimal y = 3.57m;
string h = String.Format( "item {0} sells at {1:C}", x, y );
Console.WriteLine(h);
ÔÚÎҵĻúÆ÷ÉÏ£¬¿ÉÒԵõ½ÏÂÃæµÄÊä³ö£º
item 16 sells at £¤3.57
Ò²ÐíÄãµÄ»úÆ÷ÉϵÄÊä³öºÍÕâ¸ö²»Ì«Ò»Ñù¡£ÕâÊÇÕý³£µÄ£¬±¾ÎÄÉÔºó¾Í»á½âÊÍÕâ¸öÎÊÌâ¡£
ÔÚÎÒÃÇÈÕ³£Ê¹ÓÃÖУ¬¸ü¶àµÄÊÇʹÓÃConsole.WriteLine·½·¨À´Êä³öÒ»¸ö×Ö·û´®¡£ÆäʵString.FormatºÍ
Console.WriteLineÓкܶ๲ͬµã¡£Á½¸ö·½·¨¶¼ÓкܶàÖØÔصĸñʽ²¢ÇÒ²ÉÓÃÎ޹̶¨²ÎÊýµÄ¶ÔÏóÊý×é×÷Ϊ×îºóÒ»¸ö²ÎÊý¡£ÏÂÃæµÄÁ½¸öÓï¾ä»á²úÉúͬÑù
µÄÊä³ö¡£
Console.WriteLine( "Hello {0} {1} {2} {3} {4} {5} {6} {7} {8}", 123,
45.67, true, 'Q', 4, 5, 6, 7, '8');
string u = String.Format("Hello {0} {1} {2} {3} {4} {5} {6} {7} {8}",
123, 45.67, true, 'Q', 4, 5, 6, 7, '8');
Console.WriteLine(u);
Êä³öÈçÏ£º
Hello 123 45.67 True Q 4 5 6 7 8
Hello 123 45.67 True Q 4 5 6 7 8
2 ×Ö·û´®¸ñʽ
String.FormatºÍWriteLine¶¼×ñÊØͬÑùµÄ¸ñʽ»¯¹æÔò¡£¸ñʽ»¯µÄ¸ñʽÈçÏ£º"{ N [, M ][:
formatString ]}", arg1, ... argN£¬ÔÚÕâ¸ö¸ñʽÖУº
1£© NÊÇ´Ó0¿ªÊ¼µÄÕûÊý£¬±íʾҪ¸ñʽ»¯µÄ²ÎÊýµÄ¸öÊý
2£©
MÊÇÒ»¸ö¿ÉÑ¡µÄÕûÊý£¬±íʾ¸ñʽ»¯ºóµÄ²ÎÊýËùÕ¼µÄ¿í¶È£¬Èç¹ûMÊǸºÊý£¬ÄÇô¸ñʽ»¯ºóµÄÖµ¾ÍÊÇ×ó¶ÔÆëµÄ£¬Èç¹ûMÊÇÕýÊý£¬ÄÇô¸ñʽ»¯ºóµÄÖµÊÇÓÒ¶ÔÆëµÄ
3£© formatStringÊÇÁíÍâÒ»¸ö¿ÉÑ¡µÄ²ÎÊý£¬±íʾ¸ñʽ´úÂë
argN±íʾҪ¸ñʽ»¯µÄ±í´ïʽ£¬ºÍNÊǶÔÓ¦µÄ¡£
Èç¹ûargNÊÇ¿ÕÖµ£¬ÄÇô¾ÍÓÃÒ»¸ö¿Õ×Ö·û´®À´´úÌæ¡£Èç¹ûûÓÐformatString£¬ÄÇô¾ÍÓòÎÊýN¶ÔÓ¦µÄToString·½·¨À´¸ñʽ»¯¡£ÏÂÃæµÄ
Óï¾ä»á²úÉúͬÑùµÄÊä³ö:
public class TestConsoleApp
{
public static void Main(string[] args)
{
Console.WriteLine(123);
Console.WriteLine("{0}", 123);
Ïà¹ØÎĵµ£º
* Copyright all(c) 2005 ZhongFeng, http://blog.csdn.net/SW515 */
public class ValidateCode : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
this.CreateCheckCodeImage(GenerateCheckCode());
}
&nb ......
µÚÒ»Õ ³ÌÐòÉè¼Æ
¡¡¡¡“ÒªÏë³ÉΪÕæÕýµÄ³ÌÐòÔ±£¬ÎÒÃÇÐèÒª½øÐÐÒ»³¡Ï´Àñ¡£”
¡¡¡¡“³ÌÐò = Êý¾Ý½á¹¹ + Ëã·¨¡£”ÕâÑùµÄ¹«Ê½ºÜ¾«±Ù£¬ËüÔ½¹ýÁ˱í²ãÖ±½ÓÃèÊöÁ˳ÌÐòµÄ±¾ÖÊ¡£²»½öÈç´Ë£¬ÕâÑù¼¸¸ö¼òµ¥µÄµ¥´ÊÒ²ÈÃÎÒÃÇÃ÷°×“ÎÒÃÇÓ¦¸ÃѧϰʲôÄÚÈÝ£¿”¡£ÈËÃÇ×öÈκÎʶ¼ÓÐÒ»¶¨µÄ³ÌÐò£¬Ö»ÊÇûÓÐÒâÊ ......
Êý×é¸ÅÊö
C# Êý×é´ÓÁ㿪ʼ½¨Á¢Ë÷Òý£¬¼´Êý×éË÷Òý´ÓÁ㿪ʼ¡£C# ÖÐÊý×éµÄ¹¤×÷·½Ê½ÓëÔÚ´ó¶àÊýÆäËûÁ÷ÐÐÓïÑÔÖеŤ×÷·½Ê½ÀàËÆ¡£µ«»¹ÓÐһЩ²îÒìÓ¦ÒýÆð×¢Òâ¡£
ÉùÃ÷Êý×éʱ£¬·½À¨ºÅ ([]) ±ØÐë¸úÔÚÀàÐͺóÃ棬¶ø²»ÊDZêʶ·ûºóÃæ¡£ÔÚ C# ÖУ¬½«·½À¨ºÅ·ÅÔÚ±êʶ·ûºóÊDz»ºÏ·¨µÄÓï·¨¡£
int[] table; // not int table[];
ÁíÒ ......
ÓÉÓÚÏîÄ¿ÐèÒª,ҪʹÓÃc#Ã軸ßƵʵʱÇúÏß.
µ«ÊÇÔÚC#ÏÂÓÉÓÚÃè»Í¼ÏñʹÓõÄÊÇGDI+,Ãè»Ð§ÂʺÜÓÐÎÊÌâ.Ò»µ©ÇúÏßÌ«¶à,¾Í»áÔì³ÉCPUʹÓÃÂÊÖ±ÏßÉÏÉý,ÂíÉÏìÉýµ½100%.
ÔÚGDI+ÏÂʹÓÃË«»º³åÒ²ÎÞ¼ÃÓÚÊÂ,Ë«»º³å±¾ÉíÖ»»á½â¾öÇúÏ߶àµÄʱºòÈ«ÆÁÉÁ˸ÎÊÌâ,µ«Ãè»Ð§ÂÊ»¹ÊÇÑÏÖصÍÏÂ.
Æä¼äÓùý¶àÖÖ½â¾ö·½°¸:DRECT3D,DRIRECT2D,GDI,,,,,µÈµÈµÈµÈ ......