C # .NET common small functions and method sets

xiaoxiao2021-03-06  19

1, DateTime Digital

System.datetime CurrentTime = new system.datetime ();

1.1 Take the first day of the month

CurrentTime = system.datetime.now;

1.2 taken the previous year

INT year = currenttime.year;

1.3 take the previous month

Int month = currenttime.month;

1.4 Take the day

INT day = currenttime.day;

1.5 Take the current time

INT = currenttime.Hour;

1.6 take the front part

INT = CURRENTTIME.MINUTE;

1.7 take the second second

INT second = currenttime.second;

1.8 takes the current millisecond

INT millisecond = currenttime.millisecond;

(Variable can be available in Chinese)

2, int32.parse (variable) int32.parse ("constant") character type conversion to 32-bit digital 3, variable.tostring () character type conversion to string 12345.toString ("n"); // Generate 12,345.00 12345.toString ("c"); // Generate ¥ 12,345.00 12345.toTString ("E"); // Generate 1.234500E 004 12345.toTOSTRING ("f4"); // Generate 12345.0000 12345.toString (" x "); // Generate 3039 (16) 12345.Tostring (" P "); // Generate 1,234,500.00% 4, variable .length digital tanker length: such as: string str =" China "; int LEN = Str.Length; // LEN is a custom variable, Str is a variable name 5 of the string, system.text.Encoding.default.getbytes (variable) word conversion is converted to a ratio: Byte [] BYTSTR = system.text.Encoding.default.getbytes (STR); then get the bit length: len = bytstr.length; 6, system.text.StringBuilder (")" string is added, ( number is not the same ?), Such as: system.text.stringbuilder sb = new system.text.StringBuilder (""); sb.append ("China"); sb.append ("People"); SB.Append (Republic "); 7 , Variable. Substring (parameter 1, parameter 2); part of the interception string, parameter 1 is the number of left start positions, parameter 2 is intercepted several bits.

Such as: string s1 = str.substring (0, 2); 8, string user_ip = request.serverVariables ["remote_addr"]. ToString (); Take a remote user IP address 9, pass the proxy server to take remote user real IP address: if (! Request.ServerVariables [ "HTTP_VIA"] = null) {string user_IP = Request.ServerVariables [ "HTTP_X_FORWARDED_FOR"] ToString ();.} else {string user_IP = Request.ServerVariables [ "REMOTE_ADDR"] ToString ().; } 10, session ["Variable"]; Access Session Value; (); Empty: session.removeall (); 11, string str = request.QueryString ["Variable"]; use hyperlink to transfer variables. If you build a hyperlink in either page: in the Edit.aspx page: string str = request.queryString ["fdid"]; 12, DOC Object .CreateElement ("New Number Name"); Create an XML Document New Node 13, Parent Node .Appendchild (child); add the new child node to the XML document parent node 14, parent node .removechild (node); delete Node 15, Response Response.write ("String"); Response.write; output to the page. Response.Redirect ("URL Address"; jump to the page 16 specified by the URL 16, Char.IsWhitesPCE (string variable, bit) - logical specified position is empty characters; such as: string str = "Chinese people" Response.write (char.iswhitespace (STR, 2)); / / The result is: True, the first character is 0 bits, 2 is the third character. 17. CHAR.ISPunctuation ('character') - logical symbol is punctuation, such as: response.write ('a')); // Return: false 18, (int) 'Character' Characters are converted to numbers, check the code points, pay attention to single quotes.


New Post(0)