Small note C #

1.textbox limit input only numbers
To redefine a function KeyPress
 
private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(e.KeyChar != 8 && !Char.IsDigit(e.KeyChar))
            {
                e.Handled = true;
            }
        }

 

There is also a IsNumber, with IsDigit difference is, IsNumber determine whether it is digital, IsDigit determine whether a decimal number.
Here is passed into the function KeyPressEventArgs e, rather than EventArgs. ,
 
2.c # get the absolute path suffix file name, extension, file name.
String str = " E: \ the Test \ the Default.aspx " ;
 String filename = System.IO.Path.GetFileName (str); // filename "the Default.aspx" 
String Extension = System.IO.Path.GetExtension (str) ; // extensions "the .aspx" 
String fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension (str); // no extension of the file name "Default"

 

3. The window controls generating function
Double-click function will be generated once the generating function function name will not change, and therefore should change the name of the control after the generating function
 
4. Add forms and classes
Project -> Add windows forms
Open a new form (Form named Form2.cs)
 
Form2 form = new From2();
form.Show();

 

Add Class empathy
Functions as a reference inside the new class (new class name editfiles)
 
Editfiles editfiles = new EditFiles();
editfiles.test();

 

Class with the same name can be referenced directly
Experience: allows the code to add a class apart, read more convenient, that you can use the same class name, making reference to more convenient and can be kind of different functions somewhere else, save memory needed to open a program, save resources
 
5.C # usefulness of various documents
.cs class file. Source code is written here, mainly to see the code here. 
.resx resource file, some resources stored here, generally do not need to see. 
.csproj C # project file, open the file with the VS can directly open the project, automatically generated, you do not need to see. 
.csproj.user is a configuration file, automatically generated, the project will generate a record path, information project started procedures. You do not need to see. 
.Designer.cs design documents, automatically generated, do not need to see. 
.aspx page document is, HTML code is written in here.
 
6.C # output switch is \ r \ n
 
7. Object reference not set to an instance of an object
It occurred in a fairly interesting bug, always thought that the string can not be arbitrarily assigned when debugging, but in fact, because there is no initialization string array, not given space, and therefore can not be assigned to the array. Only string [] name = null is not using the name [i], the array must give space assigned for the job:
string[] name = new string[10]

 

 
But already assigned directly to a good array gives it is also possible
 
string[] name = null;
string[] Filename = new string[80];
name = Filename;

 

8. The difference between double and single quotation marks
 
Double quotation marks "" within a string, single quotes '' of the character
 
9. Add a reference
Tools ---> Nuget Package Manager ---> management solutions Nuget package ---> View

 

 

Guess you like

Origin www.cnblogs.com/masonmei/p/11459754.html