If you find this article through a search engine, I suggest you first look at the first article in this series, this is the second in this series, today brings you more rich C # and Visual Studio programming skills, come together to see it.
1, Datatable.hasrows
It does not belong to any framework, but it is easy to imitate a method through an extension method that does not eliminate the original code that checks whether the data table object is empty or the number of rows, but it simplifies the application's code, and here is a snippet:
<CODE> public static bool HasRows (this DataTable DataTable) {return Datatable.isnull ()? False: (Datatable.row S.count > 0); } public static bool IsNull (This object o) { return (o = = null); } To use: If (Datatable.hasrows ()) { ... } </CODE>
Other rules are still the same as extension methods.
2, Totitlecase
This method converts the first letter of each word to uppercase and the remaining letters to lowercase, for example, "look below for a sample" will be converted to "look below for a sample", TextInfo is part of the System.Globalization namespace, but it has the following issues:
The current culture
If the input string is all uppercase
The following extension methods consider both of these flaws.
<CODE> public static string Totitlecase (This string inputstring) { return Thread.CurrentThread.CurrentCulture.TextInfo. Totitlecase (inputstring. String. Empty). ToLower ()); } </CODE>
3. Explicit and Covert interface implementations
Is that important? Yes, very important, do you know the grammatical differences between them? In fact, there are fundamental differences. The implicit interface implementation on a class is by default a public method that can be accessed on the object or interface of the class. The explicit interface implementation on a class is, by default, a private method that can only be accessed through the interface and not through the object of the class. Here is the sample code:
<CODE> INTERFACE public INTERFACE imyinterface { void MyMethod (string myString); } CLASS that IMPLEMENTS the INTERFACE implicitly public myimplicitclass:imyinterface {public void MyMethod ( String myString) {// } } CLASS IMPLEMENTS the INTERFACE explicitly public Myexplicitclass:imyinterface { void Imyinterface.mymethod (string myString) {// } } Myimplicitclass instance would work with either the class or the Interface: myimplicitclass myObject = new Myimplicit Class (); Myobject.mymethod (""); IMyInterface myObject = new Myimplicitclass (); Myobject.mymethod (""); Myexplicitclass would work is only with the interface: //the following line would isn't work. Myexplicitclass myObject = new Myexplicitclass (); Myobject.mymethod (""); This would work imyinterface myObject = new Myexplicitclass (); Myobject.mymethod (""); </CODE>
4. Auto Property
It is the best way to replace a property that contains a public, two private member.
Press the TAB key two times (you need to turn on the Code snippets feature), an auto property is created, and then press the tab Auto property to take a name. The following code
<CODE> private double _total; Public double total { get {return _total;} set {_total = value;} } </CODE>
It becomes a
<CODE> public double total {get; set;} </CODE>
Note that you can still apply access specifiers based on your design, and the compiler should create private member variables for you.
5, the powerful path.combine
With its powerful features, the path.combine eliminates trailing slashes and path-related problems, makes the path string more contiguous, and contains a string path parameter.
You don't have to worry about valid delimiters or spaces in the path, and you don't have to deal with string connections when you're merging paths.
6. Quick way to write "Override" method in class
Enter override in the Code editor, press SPACEBAR, and you will see a string of class-based override methods, as shown in 2.
Figure 1 List of methods to overwrite
7. Using the extended configuration file
Thanks to app. Config (for applications) and the Web. config profile, which allows us to handle complex application-level settings, we still have to deal with the various issues facing different environment settings, referring to the settings for development, test, and production environments.
We have to revert to a specific environment for analysis, testing, or tuning part of the code, which is tedious to set up and adjust every time in the process.
For example, every recovery may have to be reset connectionstrings (connection string), and now you can use the Configsource property to solve this problem with an external file reference. For example, the following code refers to a deveploment.config external configuration file.
<connectionstrings configsource= "Configs\ development.config"/>
You can also use this useful property in the appsettings Settings section.
8. Overcoming the limitations of the String.Split method
String.Split is the ideal method for separating strings, but as far as we know, it has some limitations, such as the inability to use the "| |" or "::" character, you must use a unique single character on the keyboard as a delimiter, this disadvantage can be overcome by using the Split method provided by the Regex library, the following code shows the use of Regex split to separate a "| |" Separates strings.
<code>string delimitedstring = "String.Split | | Regex.Split "); string[] ouputstring = System.Text.RegularExpressions.Regex.Split (delimitedstring, System.Text.RegularExpressions.Regex.Escape ("| |)"); </CODE>
9. Fast switching between the HTML code view and the Design view of the element (and vice versa)
When designing an application, we spend a lot of time on the IDE, and most of the time is spent on HTML content and design views, and Visual Studio 2010 provides the ability to switch between design views and HTML code quickly.
If you are in HTML view, locate the element you want to view in Design view, and then switch to Design view, the element you want to view should be selected, and the Properties window should now also display the properties of the selected element.
Similarly, when you select an element in Design view, and then switch to Code view, the HTML code for the element you selected should be highlighted.
10. Quickly search the data in the database
Although datasheets support the find and select methods to select rows, none of them are DataView, and DataView provides a findrows method that can be used to create indexes on a column sequence, so it is faster.
Hopefully these tips will help you save valuable programming time and try it out!