Csharp Ide
Csharp Ide
The Visual Studio integrated development environment (IDE) is a collection of development tools exposed through
a common user interface. Some of the tools are shared with other Visual Studio languages, and some, such as the
C# compiler, are unique to Visual C#. This topic provides links to the most important Visual C# tools.
Related Topics
TITLE DESCRIPTION
Walkthrough: Create a Simple Application Provides an overview of many of the features and tools
included in Visual Studio for application development.
Creating Solutions and Projects Describes how to create a project that contains all the source
code files, resource files such as icons, references to external
files, and configuration data such as compiler settings.
Writing Code Describes Visual Studio tools that help you modify and
manipulate text, code, and markup, insert and configure
controls and other objects and namespaces, and add
references to external components and resources.
Writing Code Provides links to procedures about how to use the Find and
Replace window, Bookmarks, and the Task List and Error List
to locate lines of code.
Viewing the Structure of Code Explains how to browse hierarchies of classes, class members,
and resources.
How to: Add an Application Configuration File to a C# Project Describes how to add a configuration file (app.config) to a C#
project.
Metadata as Source Describes how the IDE enables you to view metadata as
source code.
Refactoring (C#) Lists refactoring operations that help you modify your code
without changing the behavior of your application.
Code Generation (C#) Lists code generation tools that will write portions of code for
you.
TITLE DESCRIPTION
Compiling and Building Explains how to configure debug, release, and special builds of
your Visual Studio solution.
Debugging in Visual Studio Describes how to run the Visual Studio Debugger to resolve
logic and semantic errors.
Managing Application Resources (.NET) Shows how to add or edit resources for your project, such as
strings, images, icons, audio, and files.
Dotfuscator Community Edition (CE) Explains how to set up and start using the free PreEmptive
Protection - Dotfuscator Community Edition to protect .NET
assemblies from reverse-engineering and unauthorized use
(such as unauthorized debugging).
See Also
C#
Getting Started with C#
C# Reference
How to: Add an Application Configuration File to a
C# Project
10/31/2017 • 1 min to read • Edit Online
By adding an application configuration file (app.config file) to a C# project, you can customize how the common
language runtime locates and loads assembly files. For more information about application configuration files, see
How the Runtime Locates Assemblies.
NOTE
UWP apps don't contain an app.config template.
When you build your project, the development environment automatically copies your app.config file, changes the
file name of the copy to match your executable, and then moves the copy to the bin directory.
To add an application configuration file to your C# project
1. On the menu bar, choose Project, Add New Item.
The Add New Item dialog box appears.
2. Expand Installed, expand Visual C# Items, and then choose the Application Configuration File template.
3. In the Name text box, enter a name, and then choose the Add button.
A file that's named app.config is added to your project.
See Also
Managing Application Settings (.NET)
Configuration File Schema
Configuring Apps
How to: Configure an App to Target a .NET Framework Version
Using the Visual Studio Development Environment for C#
Metadata as Source
10/31/2017 • 1 min to read • Edit Online
Metadata as source enables you to view metadata that appears as C# source code in a read-only buffer. This
enables a view of the declarations of the types and members (without implementations). You can view metadata as
source by running the Go To Definition command for types or members whose source code is not available from
your project or solution.
NOTE
When you try to run the Go To Definition command for types or members that are marked as internal, the integrated
development environment (IDE) does not display their metadata as source, regardless of whether the referencing assembly is
a friend or not.
You can view metadata as source in either the Code Editor or the Code Definition window.
Refactoring is the process of improving your code after it has been written by changing the internal structure of
the code without changing the external behavior of the code. The following refactoring features are available in
Visual Studio for C#:
Change Method Signature
Encapsulate Field
Extract Interface
Extract Method
Inline Temporary Variable
Move Type to Matching File
Rename
Sync Type and Filename
See Also
Using the Visual Studio Development Environment for C#
Change a method signature in C#
10/31/2017 • 1 min to read • Edit Online
TIP
Use the Preview reference changes checkbox to see what the result will be before committing to it.
4. When you are finished, press the OK button to make the changes.
See Also
Refactoring (C#)
Preview Changes
Encapsulate a field in C#
10/31/2017 • 1 min to read • Edit Online
What: Lets you turn a field into a property, and update all usages of that field to use the newly created property.
When: You want to move a field into a property, and update all references to that field.
Why: You want to give other classes access to a field, but don't want those classes to have direct access. By
wrapping the field in a property, you could write code to verify the value being assigned, for example.
How:
1. Highlight or place the text cursor inside the name of the field to encapsulate:
SELECTION DESCRIPTION
Encapsulate field (and use property) Encapsulates the field with a property, and updates all
usages of the field to use the generated property
Encapsulate field (but still use field) Encapsulates the field with a property, but leaves all
usages of the field untouched
The property will be immediately created and references to the field will be updated, if selected.
TIP
Use the Preview changes link in the popup window to see what the result will be before committing to it.
See Also
Refactoring (C#)
Preview Changes
Extract an interface in C#
10/31/2017 • 1 min to read • Edit Online
What: Lets you create an interface using existing members from a class, struct or interface.
When: You have several classes, structs or interfaces with methods that could be made common and used by
other classes, structs or interfaces.
Why: Interfaces are great constructs for object-oriented designs. Imagine having classes for various animals (Dog,
Cat, Bird) which might all have common methods, such as Eat, Drink, Sleep. Using an interface like IAnimal would
allow Dog, Cat, and Bird to have a common "signature" for these methods.
How:
1. Highlight the name of the class to perform the action on, or just put the text cursor somewhere in the class
name.
New interface name The name of the interface to be created. This will default to
IClassName, where ClassName is the name of the class
you selected above.
New file name The name of the file which will be generated that will
contain the interface. As with the interface name, this will
default to IClassName, where ClassName is the name of
the class you selected above.
Select public members to form interface The items to extract into the interface. You may select as
many as you wish.
4. Click OK.
The interface will be immediately created in the file of the name specified. Additionally, the class you
selected will now implement that interface.
See Also
Refactoring (C#)
Extract a method in C#
10/31/2017 • 1 min to read • Edit Online
What: Lets you turn a fragment of code into its own method.
When: You have a fragment of existing code in some method that needs to be called from another method.
Why: You could copy/paste that code, but that would lead to duplication. A better solution is to refactor that
fragment into its own method which can be called freely by any other method.
How:
1. Highlight the code to be extracted:
TIP
You can also update comments and other strings to use this new name, as well as preview changes before saving,
using the checkboxes in the Rename box which appears at the top right of your IDE.
3. When you're happy with the change, click the Apply button or press Enter and the changes will be
committed.
See Also
Refactoring (C#)
Preview Changes
Inline a temporary variable with C#
10/31/2017 • 1 min to read • Edit Online
What: Lets you remove the use of a temporary variable and replace it with the actual code instead.
When: The use of the temporary variable makes the code harder to understand.
Why: Removing a temporary variable may make the code easier to read in certain situations
How:
1. Highlight or place the text cursor inside the temporary variable to be inlined:
See Also
Refactoring (C#)
Move a type to a matching file in C#
10/31/2017 • 1 min to read • Edit Online
What: Lets you move the selected type to a separate file with the same name.
When: You have multiple classes, structs, interfaces, etc. in the same file which you want to separate.
Why: Placing multiple types in the same file can make it difficult to find these types. By moving types to files with
the same name, code becomes more readable and easier to navigate.
How:
1. Highlight or place the text cursor inside the name of the type to move:
See Also
Refactoring (C#)
Rename a code symbol in C#
10/31/2017 • 1 min to read • Edit Online
What: Lets you rename identifiers for code symbols, such as fields, local variables, methods, namespaces,
properties and types.
When: You want to safely rename something without having to find all instances, and copy/paste the new name.
Why: Copy and pasting the new name across an entire project would likely result in errors. This refactoring tool
will accurately perform the renaming action.
How:
1. Highlight or place the text cursor inside the item to be renamed:
TIP
You can also update comments and other strings to use this new name, as well as preview changes before saving,
using the checkboxes in the Rename box which appears at the top right of your IDE.
4. When you're happy with the change, click the Apply button or press Enter and the changes will be
committed.
NOTE
If you use a name that already exists which would cause a conflict, the Rename box in your IDE will warn you.
See Also
Refactoring (C#)
Preview Changes
Sync a type to a filename, or a filename to a type in
C#
10/31/2017 • 1 min to read • Edit Online
This feature is available in Visual Studio 2017 and later. Additionally, .NET Standard projects are not yet
supported for this refactoring.
What: Lets you rename a type to match the filename, or rename a filename to match the type it contains.
When: You have renamed a file or type and haven't yet updated the corresponding file or type to match.
Why: Placing a type in a file with a different name, or vice-versa, it difficult to find what you're looking for. By
renaming either the type or filename, code becomes more readable and easier to navigate.
How:
1. Highlight or place the text cursor inside the name of the type to synchronize:
See Also
Refactoring (C#)
Code generation features for C#
10/31/2017 • 1 min to read • Edit Online
Visual Studio can help generate portions of source code for you, letting you focus on the real work. The following
code generation features are available in Visual Studio for C#:
Generate Class/Type
Generate Method
Generate Field/Property/Local
Generate Constructor
Generate Override
Generate XML Documentation Comments
Implement Abstract Class
Implement Interface
Introduce Local Variable
See Also
Using the Visual Studio Development Environment for C#
Generate a class or type in C#
10/31/2017 • 1 min to read • Edit Online
What: Lets you immediately generate the code for a class or type.
When: You introduce a new class or type and want to properly declare it, automatically.
Why: You could declare the class or type before using it, however this feature will generate the class or type
automatically.
How:
1. Place your cursor on the line where there is a red squiggle indicating you've used a class that doesn't yet
exist.
SELECTION DESCRIPTION
Generate class 'TypeName' in new file Creates a class named TypeName in a file named
TypeName.cs/.vb
Generate class 'TypeName' Creates a class named TypeName in the current file.
SELECTION DESCRIPTION
Generate nested class 'TypeName' Creates a class named TypeName nested inside the
current class.
Generate new type... Creates a new class or struct with all of the properties you
specify.
TIP
Use the Preview changes link at the bottom of the preview window to see all of the changes that will be made
before making your selection.
3. If you select the Generate new type... item, a dialog box will pop up that allows you to perform some
additional actions.
SELECTION DESCRIPTION
Name This cannot be changed and will be the name you already
typed.
File Name You can create a new file or you can add the type to an
existing file.
4. The class/struct will be created automatically with the constructor inferred from its usage.
See Also
Code Generation (C#)
Preview Changes
Generate a method in C#
10/31/2017 • 1 min to read • Edit Online
TIP
Use the Preview changes link at the bottom of the preview window to see all of the changes that will be made
before making your selection.
3. The method will be created automatically with any parameters inferred from its usage.
See Also
Code Generation (C#)
Preview Changes
Generate a field, property, or local in C#
10/31/2017 • 1 min to read • Edit Online
What: Lets you immediately generate the code for a previously undeclared field, property, or local.
When: You introduce a new field, property or local while typing and want to properly declare it, automatically.
Why: You could declare the field, property or local before using it, however this feature will generate the
declaration and type automatically.
How:
1. Place your cursor on the line where there is a red squiggle indicating you've used a field, local or property
that doesn't yet exist.
TIP
Use the Preview changes link at the bottom of the preview window to see all of the changes that will be made
before making your selection.
3. The field, property or local will be created automatically with the type inferred from its usage.
See Also
Code Generation (C#)
Preview Changes
Generate a constructor in C#
10/31/2017 • 1 min to read • Edit Online
What: Lets you immediately generate the code for a new constructor on a class.
When: You introduce a new constructor and want to properly declare it, automatically.
Why: You could declare the constructor before using it, however this feature will generate it, with the proper
parameters, automatically.
How:
1. Place your cursor on the line where there is a red squiggle indicating you've used a constructor that doesn't
yet exist.
TIP
Use the Preview changes link at the bottom of the preview window to see all of the changes that will be made
before making your selection.
3. The constructor will be created automatically with any parameters inferred from its usage.
See Also
Code Generation (C#)
Preview Changes
Generate an override in C#
10/31/2017 • 1 min to read • Edit Online
What: Lets you immediately generate the code for a any method which can be overridden from a base class.
When: You want to override a base class method and generate the signature automatically.
Why: You could write the method signature yourself, however this feature will generate the signature
automatically.
How:
1. Type the override keyword, followed by a space, where you would like to insert an overridden method
signature and an IntelliSense dropdown will appear.
2. Select the method you would like to override from the base class by clicking it with the mouse, or navigating
to it with the keyboard and pressing Enter.
TIP
Use the Property icon to show or hide Properties in the list.
Use the Method icon to show or hide Methods in the list.
3. The selected method or property will be added to the class as an override, ready to be implemented.
See Also
Code Generation (C#)
Generate XML documentation comments in C#
10/31/2017 • 1 min to read • Edit Online
What: Lets you immediately generate the base XML required to document the selected element.
When: You want to create XML Document Comments for later processing by a documentation tool like Sandcastle.
Why: You could manually create the entire comment block yourself, however this will save time and improve
accuracy by generating the base template and additional elements.
How:
1. Place your text cursor above the element you want to document, for example, a method.
2. Next, type /// (3 forward slashes) which will automatically create the base template and any additional
elements as necessary. For example, when commenting a method, it will generate the <summary> tags as
well as a <param> tag for every parameter that is passed to the method, and a <returns> tag to document
what the method returns.
3. Complete the comments and add any additional information you feel is necessary.
See Also
Code Generation (C#)
XML Documentation Comments (C# Programming Guide)
Implement an abstract class in C#
10/31/2017 • 1 min to read • Edit Online
What: Lets you immediately generate the code required to implement an abstract class.
When: You want to inherit from an abstract class.
Why: You could manually implement all abstract members one-by-one, however this feature will generate all
method signatures automatically.
How:
1. Place your cursor on the line where there is a red squiggle indicating you have inherited from an abstract
class but have not implemented all required members.
See Also
Code Generation (C#)
Preview Changes
Implement an interface in C#
10/31/2017 • 1 min to read • Edit Online
What: Lets you immediately generate the code required to implement an interface.
When: You want to inherit from an interface.
Why: You could manually implement all interface one-by-one, however this feature will generate all method
signatures automatically.
How:
1. Place your cursor on the line where there is a red squiggle indicating you have referenced an interface but
have not implemented all required members.
TIP
Use the Implement interface explicitly option to preface each generated method with the interface name to avoid
name collisions.
See Also
Code Generation (C#)
Preview Changes
Introduce a local variable in C#
10/31/2017 • 1 min to read • Edit Online
What: Lets you immediately generate a local variable to replace an existing expression.
When: You have code which could be easily reused later if it were in a local variable.
Why: You could copy and paste the code multiple times to use it in various locations, however it would be better to
perform the operation once, store the result in a local variable, and use the local variable throughought.
How:
1. Highlight the expression that you want to assign to a new local variable.
TIP
Use the Preview changes link at the bottom of the preview window to see all of the changes that will be made
before making your selection.
3. The local variable will be created automatically with the type inferred from its usage. Give the new local
variable a new name by typing it.
NOTE
You can use the ...all occurences of... menu option to replace every instance of the selected expression found, not
just the one you have specifically highlighted.
See Also
Code Generation (C#)
Preview Changes