C#-vs string, date, time, and time period

Source: Internet
Author: User
Tags ole

    • Small knowledge
A hash table, an in-memory object, uses a fast hashtable when the dictionary tables, record primary keys and content. @, encountered escape character, not escaped, direct output, that is. The escape character is a backslash/all of the built-in types are described in class and structure. Value types are used with structs, reference types, and classes. such as int with system. Int32 structure, double with system. Double structure, bool with system. Boolean structure. For a class, NULL is no reference to a string, and an empty string is also a reference object, except that the object is empty.
    • String class
The string type is actually an object of the string class, and the strings, instances of the class are objects. The object of the string class cannot be directly modified by creating a new string object, and then modifying the string reference to the new object to implement, as described later in the StringBuilder class, the string object can be modified directly. The string class is in the System namespace property. The string object name. Length method. String.Compare ("String 1", "String 2", optional case-sensitive), compare two strings, consider the language and culture of a country. returns int (1, greater than; 0 equals;-1 less than); String.Compare ("String 1", string 1 start position, "String 2", string 2 start position, selected length)string.compareordinal ("String 1", "String 2") is static, comparing two strings, regardless of the language and culture of the country. In the comparison method, this is the quickest, because it is static, and does not consider internationalization. String. Concat ("String 1", "String 2", any of the ...    Static, returns the concatenated string, as with the. NET override arithmetic operator +, because it overrides the string, so it is not meaningless to add a reference.    String.copy ("String 1") is static, returns a copy of the new string, (as with the Copy object, returns the copy Result-object), as with the. NET override assignment operator =, so it is not a copy reference. String. Equals ("String 1", "String 2"), "String 1". Equals ("String 2"), both static and instance, returns bool, same as the. NET rewrite's judgment operator = =, so it is not a two Boolean value to compare.    Static is the same as compare (), non-Static and CompareTo (), static because there is no need to create objects, faster than non-static. String. Format ("{0, Length: F floating point: After decimal length}", string object name 1) is static and returns characters formatted according to the format. Specifically in the 2nd Chapter, Intern () Static, String.intern ("a"), returns a string reference, if the memory has a string object A, will return a memory address, otherwise create a, when the string is very long, in order to improve memory utilization, the problem is that,    This string object is not automatically garbage collected and needs to be reclaimed by a line when not in use.    Isinterned () Static, unlike intern (), returns NULL when not found, and so on. String.Join ("delimiter", "string array") static, with the supplied string array and delimiter, returns a string, which is connected to each element of the array, plus the delimiter string name provided in the middle of each element. Split ("delimiter"), relative to join (), returns an array of strings separated by the delimiter in the specified original string.string Object name. CopyTo (character array, number) is non-static, no return value, similar to split (split is broken down into a string array by delimiter), which is a specified number of characters copied from a string to a character array. Object name. Clone (), as with copy () but the instance method returns a reference to an object that was copied, the object referenced by the member of the copied object, and no copy, that is, shallow clone. Same as the MemberwiseClone () method.object name. CompareTo (object 1), compare () non-static version. The string name. StartsWith ("string"), similar to EndsWith (string), whether to provide the start string object name. EndsWith ("string"), whether the end of the providedThe string object name. GetEnumerator (), returns an enumerator charenumerator that enumerates the characters in the string. Specific look at the collectionThe string object name.GetHashCode (), returns the hash code of an intstring Object name. GetType (), which returns the type of the current instance of typeString object name. GetTypeCode (), which returns the type code of the current instance of typestring Object name. indexOf (char or string, optionally specifying the index at which to start the lookup, optionally specifying the number of characters to find when the previous argument is available), returns the index number of the specified character or string that the string first appears (starting at 0). Regular expressions, which enable more complex lookups of strings, appendix 3The string object name.    LastindexOf (char or string, optionally specifying the index at which to start the lookup, optionally specifying the number of characters to find when there is a previous argument), returns the index number of the specified character or string that occurred last occurrence of the string (starting at 0) The string object name, IndexOfAny (char array), that returns the index of any character that first appears in the Char array.    As with IndexOf, there are two overriding methods, with parameters specifying the start index and the number of characters to look up. The string object name. A lastindexofany (char array) that returns the index of any character in the last occurrence of the char array.    As with LastIndexOf, there are two overriding methods, with parameters specifying the start index and the number of characters to look up.         string object name [index], which returns the character string name at the specified index. Insert (Index, string 1), inserts the string 1 into the string name at the index position. The string name.  Remove (index, number of characters removed) to remove the specified number of character string names from the specified index. Replace (old character or string, new character or string), replaced with the specified character or string AllThe specified original character or stringThe string name. PadLeft (total length, optional padding character), similar to format ("{0, length}", string object name 1), returns a string with a specified number of spaces on the left, and can be set to add other symbols. The string name.    PadRight (total length, optional padding characters are not selected as spaces), returns a string with a specified number of spaces on the right, and can be set to add other symbols. The string name. Substring (start index, length can be omitted), return substring, ToCharArray (), put the string into character array by character, similar to split (), different is split with a delimiter string into a string array, here directly into the character ToLower (), Returns the Lowercase object copy, the original object is not changed to ToString (), returns the value of the string ToUpper (), returns a lowercase copy of the object, and the original object is unchangedThe string name. Trim (do not fill in the blanks to remove the first and the end of the character), return to the object copy, the beginning and ending of the space to remove, or remove the start and end of the specified character. The string name. TrimEnd (not filled out is the blank space to remove the tail of this character), return to the object copy, the end of the space to remove, or remove the start and end of the specified character.The string name. TrimStart (not filled in blanks is the first character removed), return to the object copy, the beginning of the space to remove, or remove the beginning and end of the specified character.
    • Stringbiulder class
Unlike the object of the string class, the object can be modified directly, so it is more efficient and the ability to manipulate the string is stronger because it breaks through the restrictions that cannot be directly modified. This class is created in the System.Text namespace, unlike the String class, which is not directly declared but needs to be created with new. Stringbiulder Mystringbiulder = new Stringbiulder (optional initial length, optional maximum length is the largest by default), overriding build method = new Stringbiulder ("string", when there is the first argument    The 3 parameter selects the starting position of the string, selects the length, Total capacity) property. Capacity Length Maxcapacity method.The StringBuilder object name. Append (String) returns Stringbiulder (note that direct modification, no copy, and subsequent modification methods are directly modified), with the string appended to the end. Overrides the StringBuilder object name. Append (myint variable), StringBuilder object name. Append (mybool variable), StringBuilder object name. Append ("character", number of characters repeat), StringBuilder the object name. Append (string, starting index, number of characters selected). StringBuilder object name. AppendFormat ("{0,10:f3},myfloat variable) returns Stringbiulder, ending with formatted string StringBuilder object name. Insert (Index, String), returns the StringBuilder object, unlike Append and AppendFormat, which is an optional insertion position, and overloads the StringBuilder object name. Insert (Index, string, string repetition StringBuilder object name. replace (old string or character, new string or character), return StringBuilder object, replace all old characters or string StringBuilder object name. Remove (index, quantity),    Returns the StringBuilder object StringBuilder object name. ToString (), which returns the Copy object address reference converted to a string. StringBuilder object name. Ensurecapacity (), returns the current capacity?    , whether the capacity is at least equal to a specific value StringBuilder object name. Equals (), returns a Boolean value equal to a specific object? StringBuilder object name. GetHashCode (), returns the INT hash code StringBuilder object name. GetType (), returns the type of the current object
    • DateTime structure
The datetime structure in the System namespace is a value type, saved in the stack fast, the properties and methods are less, used to replace the class; can be created without new, but recommended with new; there is no default build method, that is,. NET does not give no parameters to the build method.    The method by which the DateTime structure builds an instance. New DateTime (Year,month,day) New DateTime (Year,month,day,hour,minute,second,millisecond) New DateTime (Year,month,da Y, the time zone object MyCalendar is associated with the program globalization system that requires the specified time zone creation). Globalization.juliancalender a time zone MyCalendar = newSystem. Globalization.juliancalender ();New DateTime (a long-shaped tick number ticks is 1 for one out of 10,000 seconds from 0 o'clock A.D. January 1, 1)Attribute Mydatetime.year,mydatetime.month,mydatetime.day,mydatetime.hour,mydatetime.minute,Mydatetime.second, mydatetime.millisecond,mydatetime.ticks DateTime.Now, Static, returns the current date and time of datetimeDatetime.utcnow, Static, returns the current date and time of datetime GMTdatetime.today, Static, return datetime current date, time is 0 points (12 o'clock in the morning, not 12 o'clock Noon)Mydatetime.date, returns datetime, is the date portion of the DateTime instance, and the time portion is 0 pointsMydatetime.dayofweek, return DayOfWeek, Sunday 0, week 66mydatetime.dayofyear, return int, between 1~366Mydatetime.timeofday, returns a timespan that gets the time-division tick of a DateTime instanceMethodDatetime.compare (datetime1,datetime2), static, returns an int, comparing two DateTime instances. You can use the operators that are overridden for datetime > >= < <= = = = To compare datetime instances, which return Boolean values    mydatetime.compareto (DATETIME1), returns an int, comparing two datetime instances.     Mydatetime.getdatetimeformats (? ), returns an array of string[] strings, which are the values of the DateTime instance, containing all the formats supported by DateTime?     datetime.daysinmonth (year,month), static, returns the number of days in an int for a specific year and month      Datetime.isleapyear (year), Static, returns a Boolean value, whether the leap year is 366 days     datetime.parse ("string written by date and time 1/15/2015   21:02:05 "), Static, returns a DateTime conversion, the overridden method can be converted into a specific culture-related date format, globalization     datetime.equals (datetime1,datetime2), Static, Returns whether the Boolean value is equal to the = = that is overridden for DateTime.     datetime1.equals (DateTime2), with an instance version, also returns a Boolean value     Mydatetime.tofiletime (), Returns the long operating system time information, which is the timestamp timestamps, and the timestamp timestamps is the number of one out of 10,000 seconds starting January 1, 1601 0 o'clock.     datetime.fromfiletime (timestamp), static, time information to return a DateTime file     mydatetime.tolocaltime (?), Returns a long converts the current global unification time GMT to the time of the computer's selected timezone     mydatetime.tolongdatestring (), returns a string, converts the date part to the "Thursday , January "    mydatetime.toshortdatestring (), returns string, converts the date part to" 1/15/2015 "   &nbsP;mydatetime.tolongtimestring (), return string, convert the time section to "11:02:05 PM"     mydatetime.toshorttimestring () , return string, convert the time section to "11:02 PM"     mydatetime.tostring (optional as "Yyyy-mm-dd HH:mm:ss"), return string,    Mydatetime.touniversaltime (), returns datetime, converts the current local time, which is the computer's selected time zone, to the same time worldwide UTC GMT      Mydatetime.tooadate (), return double, convert to OLE auto date?     datetime.fromoadate (? ), Static, return datetime to OLE object link or embed      Datetime.paneexact (String written by date and time), static, returns a DateTime conversion, the string must match a specific format, that is, the format is only one     Mydatetime.add (Mytimespan), which returns a reference to a datetime new instance, gives the DateTime an interval timespan, and overrides the same function.     mydatetime.subtract (Mytimespan or Mydatetime), returning a timespan, overriding operator-same effect.         Mydatetime.addyears (number represents years), returns a reference to a datetime new instance. Write negative numbers represent a decrease.     mydatetime.addmonths (number for number of months), returns a reference to the DateTime new instance.     mydatetime.adddays (number for days), returns a reference to the DateTime new instance.     mydatetime.addhours (number for hours), returns a reference to the DateTime new instance.     MydatEtime.addminutes (the number represents the number of minutes) that returns a reference to the DateTime new instance.     Mydatetime.addseconds (number for seconds), returns a reference to the DateTime new instance.     mydatetime.addmilliseconds (number for milliseconds), returns a reference to the DateTime new instance.     mydatetime.addticks (number for ticks), returns a reference to the DateTime new instance.        Mydatetime.gethashcode (?), return int hash code     Mydatetime.gettype (), return type instance types     
    • TimeSpan class
Representative time period construction methodTimeSpan Mytimespan = new TimeSpan (number of hours, minutes, seconds) TimeSpan Mytimespan = new TimeSpan (number of days, hours, minutes, seconds) TimeSpan Mytimespan = new TimeSpan (days, hours, minutes, seconds, millimeters) TimeSpan MyT Imespan = new TimeSpan (tick count) can be added to a time period to an instance datetime, such as Mydatetime = Mydatetime + mytimespan or mydatetime + =MytimespanProperty.     Mytimespan.days, return int, number of days part mytimespan.hours, return int, hour part mytimespan.minutes, return int, minute part mytimespan.seconds, return int, second part Mytimespan.milliseconds, return int, millisecond part, 1 per thousand seconds mytimespan.ticks, return long, convert to tick count, one out of 10,000 seconds mytimespan.totaldays, return double, convert to Days mytimespan.totalhours, return double, convert to hour mytimespan.totalminutes, return double, convert to minute mytimespan.totalseconds, return double, go    Into seconds mytimespan.totalmilliseconds, return double, convert to millisecond method. Timespan.compare (MYTIMESPAN1,MYTIMESPAN2), returns int Mytimespan.compareto (MYTIMESPAN1,MYTIMESPAN2), returns INT, Compare () and CompareTo () are all returned inttimespan.equals (MYTIMESPAN1,MYTIMESPAN2), returns BOOLMytimespan.equals (MYTIMESPAN2), returns BOOL, with the same function as the operator = = for the timespan overload (number of days), returns a TimeSpan, and converts to a timespan. Represents    Timespan.fromhours (Hours), returns a TimeSpan, converted to TimeSpan. Represents the Timespan.fromminutes (number of minutes), returns a TimeSpan, and converts to a timespan.    Timespan.fromseconds (seconds), returns a TimeSpan, converted to a TimeSpan. Represents Timespan.frommilliseconds (in milliseconds), returns a TimeSpan, and translates to TimeSpan.    Timespan.fromticks (tick count), returns a TimeSpan, converted to a TimeSpan. Represents Timespan.parse ("string written in time period 1/15/2015 21:02:05"), returning a TimeSpan mytimespan.tostring (optional format?) ), returns a string Mytimespan.duration (), returns a TimeSpan, takes the absolute value mytimespan.negate (), returns a TimeSpan, and takes the opposite numberMytimespan.add (TimeSpan), which returns a TimeSpan, plus, with the same function as the operator for the timespan overloadMytimespan.subtract (TimeSpan), which returns a TimeSpan, minus, with the operator that is overloaded with the timespan-the same effect    Mytimespan.gethashcode (), returns an int, returns the hash code that represents the primary key saved in the hash table, and the value represents the memory address? Mytimespan.gettype (), returns the type

C#-vs string, date, time, and time period

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.