C # common functions

xiaoxiao2021-03-06  39

1, DateTime digital system.datetime currenttime = new system.datetime (); 1.1 Net ago, the month-time time, the second currenttime = system.datetime.now; 1.2 Before the year INT year = currenttime.year; 1.3 take the prior month INT month = CURRENTTIME.MONTH; 1.4 Take Front Day INT Day = CURRENTTIME.DAY; 1.5 Take the current INT = CURRENTTIME.HOUR; 1.6 Take the Prior INT = CURRENTTIME.MINUTE; 1.7 Take the second second = CurrentTime.second; 1.8 Take the current millisecond INT millisecond = currentTime.milliseCond; (variable available 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.toString ("e"); / / Generate 1.234500e 004 12345.toString ("f4"); // Generate 12345.0000 12345.toString ("X"); // Generate 3039 (16) 12345.toTString ("P"); // Generate 1,234,500.00%

4, variable .length digital snap length: string str = "China"; int LEN = str.length; // is a custom variable, Str is a variable name 5, System. TEXT.Encoding.default.getbytes (variable) word conversion to a ratio code such as: Byte [] ByTSTR = System.Text.Encoding.default.getbytes (STR); then get the bit length: len = bytstr.length; 6, System.Text.StringBuilder ("") String is added, (is 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 left start position, The parameter 2 is intercepted several times. 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.

转载请注明原文地址:https://www.9cbs.com/read-70519.html

New Post(0)