Compiling C # program literacy with VS2010

Source: Internet
Author: User

0.

The Properties folder defines the property of your assembly the project Properties folder typically has only one AssemblyInfo.cs class file that holds information about the assembly, such as name, version, and so on, which generally correspond to the data in the project Properties panel and do not need to be manually written

The Bin directory is used to save the project post-build assembly, it has debug and release two versions, respectively, the corresponding folder is Bin/debug and Bin/release, this folder is the default output path, we can through: Project properties, Configuration Properties, Output path to modify.

The obj directory is used to hold the compilation results for each module, and in. NET, the compilation is done in sub-modules, and the compilation is merged into one after completion. DLL or. exe is saved to the bin directory. Because incremental compilation is the default at compile time, which means that only the changed modules are recompiled, obj saves the compilation results of each module to speed up the compilation. Whether you are using incremental compilation, you can set it by using incremental compilation, Advanced, Configuration Properties, project properties.

1. Several ways to create a string object:

      

static void Main (string[] args) {//strings, strings concatenated string fn            Ame, lname;            fname = "Rowan";            LName = "Atkinson";            String fullname = fname + lname;            Console.WriteLine ("Full Name: {0}", fullname);            By using the string constructor char[] Letters = {' H ', ' e ', ' l ', ' l ', ' o '};            String greetings = new string (Letters);            Console.WriteLine ("Greetings: {0}", Greetings);            method returns the string string[] Sarray = {"Hello", "from", "tutorials", "point"};            String message = String.Join ("", Sarray);            Console.WriteLine ("Message: {0}", message);            Formatting methods for conversion values datetime waiting = new DateTime (2012, 10, 10, 17, 58, 1);            string chat = String.Format ("Message sent at {0:t} on {0:d}", waiting);            Console.WriteLine ("Message: {0}", chat);        Console.readkey (); }

2.

    • When you Create a struct object using the New operator, the appropriate constructor is called to create the structure. Unlike classes, structs can be instantiated without the use of the NEW operator.
    • If you do not use the New operator, the field is assigned only after all fields have been initialized and the object is used

3.

Classes and structs have the following basic differences:

    • A class is a reference type, and a struct is a value type.
    • The structure does not support inheritance.
    • Structs cannot declare a default constructor.

4. Enumeration examples:

Using System;namespace enumapplication{   class Enumprogram   {      enum days {Sun, Mon, Tue, Wed, Thu, Fri, Sat};
   static void Main (string[] args)      {         int weekdaystart = (int) Days.mon;         int weekdayend = (int) Days.fri;         Console.WriteLine ("Monday: {0}", Weekdaystart);         Console.WriteLine ("Friday: {0}", weekdayend);         Console.readkey ();}}}   

5. The default access identifier for the class is internal, and the member's default access identifier is private.

6. The name of the constructor is exactly the same as the name of the class, and it does not have any return type.

7.

A destructor for a class is a special member function of a class that executes when the object of the class goes out of scope.

The name of the destructor is prefixed with a tilde (~) in front of the name of the class, and it does not return a value or any parameters.

Destructors are used to release resources before ending programs, such as closing files, freeing memory, and so on. Destructors cannot be inherited or overloaded.

8.

 class   line { private  double  length; //       length of the line  public  Line () //  constructor   {Console.WriteLine ( "     ~line ()  destructor   {Console.WriteLine (   object deleted   "      ); }

9.

We can use the static keyword to define a class member as static. When we declare a class member to be static, it means that no matter how many classes of objects are created, there will only be one copy of that static member.

The keyword static means that there is only one instance of the member in the class. Static variables are used to define constants, because their values can be obtained by invoking the class directly without creating an instance of the class . A static variable can be initialized outside the definition of a member function or class. You can also initialize static variables inside the definition of a class.

10. You can also declare a member function as static. Such a function can only access static variables. A static function already exists before the object is created.

11. A class can derive from more than one class or interface, which means that it can inherit data and functions from multiple base classes or interfaces.

12. In the subclass constructor, initialize the member variable of the parent class. (when subclasses are instantiated, the parent class object should be created before the subclass object is created)

usingSystem;namespacerectangleapplication{classRectangle {//member Variables      protected Doublelength; protected Doublewidth;  PublicRectangle (DoubleLDoublew) {length=l; Width=W; }       Public DoubleGetarea () {returnLength *width; }       Public voidDisplay () {Console.WriteLine ("length: {0}", length); Console.WriteLine ("width: {0}", width); Console.WriteLine ("area: {0}", Getarea ()); }   }//End Class Rectangle   classTabletop:rectangle {Private DoubleCost ;  PublicTabletop (DoubleLDoubleW):Base(L, W) {} Public DoubleGetcost () {DoubleCost ; Cost= Getarea () * -; returnCost ; }       Public voidDisplay () {Base.         Display (); Console.WriteLine ("cost: {0}", Getcost ()); }   }   classExecuterectangle {Static voidMain (string[] args) {Tabletop T=NewTabletop (4.5,7.5);         T.display ();      Console.ReadLine (); }   }}

C # does not support multiple inheritance . However, you can use interfaces to implement multiple inheritance. The following program demonstrates this

14.

Polymorphism implies a multiplicity of forms. In object-oriented programming paradigm, polymorphism often manifests as "one interface, multiple functions".

Polymorphism can be static or dynamic. In static polymorphism , the response of a function occurs at compile time. In dynamic polymorphism , the response of a function occurs at run time.

Static polymorphism: function overloading, operator overloading, not overloading function declarations with different return types

15.

C # allows you to use keyword abstraction to create an abstract class that provides an implementation of a partial class of interfaces. When a derived class inherits from the abstract class, the implementation is complete. Abstract classes contain abstract methods, and abstract methods can be implemented by derived classes. Derived classes have more specialized functionality.

Note that here are some rules about abstract classes:

You cannot create an instance of an abstract class.

You cannot declare an abstract method outside an abstract class.

you can declare a class as a sealed class by placing the keyword sealedin front of the class definition. When a class is declared as sealed , it cannot be inherited. Abstract classes cannot be declared as sealed.

  

16. Dynamic polymorphism ... I don't understand, http://www.runoob.com/csharp/csharp-polymorphism.html.

.String.       Format("({0}, {1}, {2})", length, breadth, height); string output

18. To extend or modify an abstract implementation or virtual implementation of an inherited method, property, indexer, or event, you must use the override modifier

19.

An interface uses the interface keyword declaration, which is similar to a class declaration. The interface declaration is public by default.

The interface defines the syntax contracts that should be followed when all classes inherit an interface. The interface defines the "what" part of the syntax contract, and the derived class defines the "How to" section of the syntax contract .

An interface defines properties, methods, and events, which are members of an interface. The interface contains only the declarations of the members. The definition of a member is the responsibility of the derived class. The interface provides the standard structure that a derived class should follow.

Abstract classes are somewhat similar to interfaces, but most of them are only used when only a few methods are declared by the base class by a derived class.

20. Preprocessor directives instruct the compiler to preprocess information before the actual compilation begins. Preprocessor directives are not statements, so they do not end with semicolons (;).

#define It is used to define a series of characters that become symbols.
#undef It is used to cancel the definition of a symbol.
#if It is used to test whether the symbol is true.
#else It is used to create compound conditional directives for use with #if.
#elif It is used to create compound conditional directives.
#endif Specifies the end of a conditional directive.
#line It allows you to modify the number of lines of the compiler and (optionally) output errors and warning file names.
#error It allows an error to be generated from the specified location in the code.
#warning It allows a level-one warning to be generated from the specified location of the code.
#region It allows you to specify an expandable or collapsed block of code when you use the outline attributes of Visual Studio code Editor.
#endregion

It identifies the end of the #region block.

Compiling C # program literacy with VS2010

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.