Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

C # what are the common functions and methods

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what are the common functions and methods of c #". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "what are the common functions and methods of c #"?

1. DateTime digital type

System.DateTime currentTime=new System.DateTime ()

1.1 take the current year, month, day, hour, minute and second

CurrentTime=System.DateTime.Now

1.2 take the current year

Int year = currentTime.Year

1.3 take the current month

Int month = currentTime.Month

1.4 take the current day

Int day = currentTime.Day

1.5 take the current tense

Int = currentTime.Hour

1.6 take the current score

Int score = currentTime.Minute

1.7 take the current second

Int seconds = currentTime.Second

1.8 take the current millisecond

Int milliseconds = currentTime.Millisecond;// (variables can be in Chinese)

1.9 Chinese date display-year, month, day and hour

String strY=currentTime.ToString ("f"); / / does not display seconds

1.10 date in Chinese is displayed _ year and month

String strYM=currentTime.ToString ("y")

1.11 date in Chinese to display the day of the month

String strMD=currentTime.ToString ("m")

1.12 take Chinese year, month and day

String strYMD=currentTime.ToString ("D")

1.13 take the current time in the format: 14:24

String strT=currentTime.ToString ("t")

1.14 take the current time, format: 2003-09-23T14:46:48

String strT=currentTime.ToString ("s")

1.15 take the current time in the format: 2003-09-23 14purl 48purl 30Z

String strT=currentTime.ToString ("u")

1.16 take the current time in the format: 2003-09-23 14:48

String strT=currentTime.ToString ("g")

1.17 take the current time in the format: Tue, 23 Sep 2003 14:52:40 GMT

String strT=currentTime.ToString ("r")

1.18 date time after n days of obtaining the current time

DateTime newDay = DateTime.Now.AddDays

2. Int32.Parse (variable) Int32.Parse ("constant")

Character conversion to 32-bit digital conversion

3. Variable .ToString ()

Character conversion to string

12345.ToString ("n"); / generate 12345.00 12345.ToString ("C"); / generate ¥12345.00 12345.ToString ("e"); / generate 1.234500e+004 12345.ToString ("f4"); / / generate 12345.0000 12345.ToString ("x"); / generate 3039 (hexadecimal) 12345.ToString ("p"); / / generate 1234500.00%

4. Variable .Length digital type

Take the string length:

String str= "China"; int Len = str.Length; / / Len is a custom variable, and str is the variable name of the string being tested

5. System.Text.Encoding.Default.GetBytes (variable)

Code conversion to bitcode

Byte [] bytStr = System.Text.Encoding.Default.GetBytes (str)

Then the bit length can be obtained:

Len = bytStr.Length

6. System.Text.StringBuilder ("")

Strings are added, (is the + sign 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)

To intercept part of a string, parameter 1 is the starting bit from the left, and parameter 2 is the number of digits to be intercepted.

Such as:

String S1 = str.Substring (0Jing 2)

8. String user_IP=Request.ServerVariables ["REMOTE_ADDR"] .ToString ()

Get the IP address of the remote user

9. Get the real IP address of the remote user through the proxy server:

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 the session value; for example, assign:

Session ["username"] = "Bush"

Value:

Object objName=Session ["username"]; String strName=objName.ToString ()

Clear:

Session.RemoveAll ()

11. String str=Request.QueryString ["variable"]

Use hyperlinks to transfer variables.

If you create a hyperlink on any page:

Click

Take a value in the Edit.aspx page:

String str=Request.QueryString ["fdid"]

12. DOC object .CreateElement ("New Node name")

Create a new node for the XML document

13. Parent node .AppendChild (child node)

Add the new child node to the parent node of the XML document

14. Parent node .RemoveChild (node)

Delete nod

15 、 Response

Response.Write ("string"); Response.Write (variable)

Output to the page.

Response.Redirect ("URL address")

Jump to the page specified by URL

16. Char.IsWhiteSpce (string variables, digits)-logical type

Check whether the specified position is an empty character

Such as:

String str= "Chinese people"; Response.Write (char.IsWhiteSpace (str,2)); / / the result is: True, * characters are 0 digits, 2 is the third character.

17. Char.IsPunctuation ('character')-logical type

Check whether characters are punctuation marks such as:

Response.Write (char.IsPunctuation ('A')); / / return: False

18. (int) 'character'

Turn the character into a number, check the code point, and note that it is in single quotes.

Such as:

Response.Write ((int) 'medium'); / / the code with the result of medium character: 20013

19. (char) Code

Turn the numbers into characters and look up the characters represented by the code.

Such as:

Response.Write ((char) 22269); / / returns the word "country".

20. Trim ()

Clear the space before and after the string

21. String variable .Replace ("substring", "replace with")

String substitution

Such as:

String str= "China"; str=str.Replace ("country", "central government"); / / change the national character to the central character Response.Write (str); / / output the result to be "central"

Again: (this is very practical)

String str= "this is a script"; str=str.Replace ("

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report