Java attack C # -- project development environment,

Source: Internet
Author: User

Java attack C # -- project development environment,

Summary of this Chapter

In the previous chapter, we learned about the development environment and how to create a project. But did not go to the Project for introduction. However, we will often deal with projects later. In this chapter, I will explain some common functions of the project. Of course, it is impossible to make it comprehensive. I think it is common.

Project Development Environment

We have all learned about creating a project. We may not know about it. That is, after creating a project. Project display structure problems. The "HelloExample" in the above chapter is an example. Let's take a look at the structure of his project.

The project structure information is as follows:

1. Solution "HelloExample" (1 Project): solution described in the previous chapter ".

2. HelloExample: Project

3. Properties: corresponds to the Properties directory in the previous chapter.

4. Reference: it is equivalent to the Build Path function of Eclipse. That is, reference the JAR package (the English version is used ). If you open it, you will find many referenced DLL files. The DLL package ends with. dll. The JAR package ends with. jar.

5. Program. cs: source code file

The reference practices are really just a little different from those of Eclipse. To learn about the reference function. I have to create a new class library. The class library is equivalent to a java project without the Main entry class. This is equivalent to creating a jar package project. I believe everyone will create a new project. Right-click solution> Add to create a project. The window is shown as follows.

Note: As shown in the figure above,. NET Framework 4 is the. NET Framework version number. Readers can choose their own.

Click "OK" and a project (Hello) will be added under the solution ). However, this project has no Main entry. Cannot be executed. Can only be referenced. It is the JAVA import package. Let's take a look after generation.

Run the two projects on the opposite side. It means that there is no difference in their project structure. When a Hello project is generated, Visual Studio creates a class for you. If you do not need it, delete it by yourself. Right-click the current class and choose Delete. Or press the shortcut key "Delete ". Then a new problem arises. What if you want to create a new class? At this time, we need to understand a simple truth. Remember that Eclipse classes are generally stored in the src directory. Sorry. C # There is no such directory. They are generally stored in the project directory. Right-click the project and choose add> new project.

Note that the above image is just the form of the last step. Another solution is the same as that in the previous chapter. As you may have understood. Right-click solution to create a project, and right-click project to create a project. In fact, you can click the class on this interface to create a new class. However, I still want to select the new item. Let's see what it looks like.

Taking a look at the above picture, I have drawn two commonly used ones. I believe that the readers will know at a glance that it is used to create classes and interfaces. Here we choose to create a class. Enter the class name in the lower part of the interface. The author named Activator. The class name must contain uppercase letters. The two sides are the same. Let's take a look at what he generated.

 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5  6 namespace Hello 7 { 8     class Activator 9     {10     }11 }

First look at the red part above. Next we need to modify it on him. Add the code we need. I will modify it first. The Code Section will be analyzed and explained below. Let's take a look at the changes. Output Hello world.

 public class Activator    {        public void Print()        {            Console.WriteLine("Hello world");        }    }

Okay. After the DLL package project is created, the DLL package is referenced. Right-click the reference directory mentioned above.

The above picture has three common functions that need attention. I will give them an example. If you are interested in other things, study them on your own. SORRY.

1. Add reference (R): This is where the DLL package is referenced. There are reference solutions and reference third-party DLL packages.

2. Add service reference (S): This is to reference the Web service. Does JAVA have Web Services. I believe everyone understands this.

3. Manage NuGet packages (N): You have used Maven. Is equivalent to the Maven function. Is used to find the desired DLL package on the network. Of course, Maven features. Not only.

Let's take a look at the project that adds and references this part. Click him.

The form popped up above is the working interface for referencing the DLL package. We will find four root directories.

1. Assembly: Used to reference the. NET Framework internal DLL package. It is equivalent to the package in Eclipse's JRE.

2. Solution: reference the project under the current solution. We can see that it lists all project projects. I believe everyone knows that Eclipse's JAVA Build Path Interface contains a menu item called Projects. I think it is equivalent to him.

3. Com: I cannot say this. A large number of com components are included. Because I am not very familiar with this part. So...

4. browsing: This is to reference a third-party DLL package. Is to reference someone else to develop the DLL package. It is equivalent to adding a JAR package in Eclipse. I believe you will use this root directory. The corresponding list is the history you reference.

Whether you are using the browser feature (that is, referencing a third-party DLL package) or using a solution reference. After successful reference, the corresponding DLL package name appears in the reference directory. For example, the red circle section:

I was wondering what it looks like to determine the DLL name is Hello. I mean, if I don't want to call Hello, but want to change it to another name, isn't it? So I did an experiment. But a strange result is found. The author modified the DLL name generated by the project. If the reference is carried out in the third method, browsing is used. It can be changed to the corresponding name. However, if the reference is a solution method, the name remains unchanged. If you modify the project name, the name is changed. How to modify the DLL name generated by each project. Right-click the corresponding project, and the pop-up form is as follows:

We have seen this interface many times. I will list several common functions. As follows:

1. Set as startup project (A): If the solution has multiple project projects containing the Main entry class, you do not want to start the default project of the solution. This project can be used for implementation at this time.

2. Uninstall the Project (L): this function is like the Close Project function of Eclipse.

3. Open the folder in the file resource manager: Do you want to talk about it?

4. Rename (M): I will discuss it. This is how to modify the project name.

5. Attribute (R): This is the focus. It is used to modify the project information.

After learning about the form above, Let's click the "properties" menu to see what the form will look like.

In the preceding figure, the Assembly name in the "application" menu is described as how to change the DLL name. For ease of understanding, I will only explain three common ones: application, generation, and debugging.

1. Application: Modify project information. Including the DLL file name, startup object, and the version of the. NET Framework of the current project. The reader can see the information from the picture above.

2. Generate: the information used for generation. Note that you can set where to store the file after the file is generated successfully.

3. debugging: refers to the debugging operation information. It is important to set the running parameters. I wonder whether I have understood the Arguments menu items of the Debug Configurations form of Eclipse.

When I see this, I don't know whether readers have such ideas. If the project has property information, there is no property information for the solution. I can only say yes. But I will not introduce it. Same practice. (I am actually using a few, but I just used a single start and multiple start. Not on the table)

Okay. At this point, I believe that readers all know how to reference a DLL or project. After the reference is successful, I want to modify the Main entry class. That is, the Program. cs source code file. The author changes the code in the previous chapter to the following:

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace HelloExample{    class Program    {        static void Main(string[] args)        {            Hello.Activator activator = new Hello.Activator();            activator.Print();        }    }}

The above code function is very simple, that is, it calls the Activator class in the DLL package developed by the author and prints Hello world. But there are two points to consider.

1. namespace Keyword: Everyone knows the JAVA package keyword. The text is called a package .. NET is called a namespace.

2. using Keyword: Needless to say, it is the JAVA import keyword.

I thought for a moment: There are N project projects under the solution, and N namespaces under one project. A namespace has N classes. Ctrl + F5 start.

Summary

The focus of this chapter is to explain the project directory. Understand the reference function. Class. The namespace and the imported namespace are empty. With this chapter, we can learn more about syntax.

Related Article

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.