Вы находитесь на странице: 1из 35

Microsoft Visual Studio 2012|Code Tips

Usman ur Rehman Ahmed


Audience Marketing Manager (AMM), Microsoft Pakistan
Code Pointers

NAMED DRAG & DROP


INTELLISENSE CTRL + SPACE
REGIONS CODE

QUICK LAUNCH PREVIEW SEARCH AND CODE CLONE


Ctrl + Q TAB SYNC ANALYSIS

AUTO –
GO TO CODE SURROUND
IMPLEMENTED
DEFINITION MAP WITH
PROPERTIES
ALL IN ONE
LINES OF DISPLAY NUMER GO TO SPECIFIC
CODE
CODE OF LINES LINE NUMBER
FRAMEWORK

PASCAL CASE METHOD METHOD OFFLINE


TYPING NAMING CHAINING HELP

Equals(object);
USE PHYSICAL
ALT + COMMENT GetHashCode();
KEYBOARD ON
HIGHLIGHT CODE BLOCK GetType();
EMULATOR
ToString();
NAMED
# region REGIONS

# endregion

– lets you specify a block of code that


you can expand or collapse

– #region name
– name is the name you want to give to
the region
– The region block must be terminated
with a #endregion directive
DRAG & DROP
CODE

Paste Code Blocks in Toolbox

– You can reuse the code without having


to type over and over again
– Place it in a toolbox under one of the
sections or create your own one
– Drag and drop as required
– It will now be available in all your
projects
Select a code block (highlight it)

Drag and Drop to Toolbox (recommended: rename)


INTELLISENSE

Ctrl Key
– IntelliSense provides
an array of options
that make language
references easily
accessible.
– Auto - suggestions
– Hold down the Ctrl key
to see through the
code hidden behind
the IntelliSense
CTRL + SPACE

Display IntelliSense
QUICK LAUNCH
Ctrl + Q

Ctrl + Q

Most Recently Open


Menus Used Options
Document
@menu @opt
@mru @doc
PREVIEW
TAB

Solution Explorer -> Preview Selected Items


SEARCH AND
SYNC

Solutions Explorer -> Search & Sync


– Enter keyword to Search for – Sync Solutions Explorer to
results within the project the currently active tab
CODE CLONE
ANALYSIS

Similar fragments of code


– Separate fragments of code
that are very similar
– Find clones and refactor them
– Find clones of a specific
fragment or find all clones in
your solution
Double Click a Clone Entry
Code Clones in Entire Solution

– "Analyze solution for Code Clones" is only available in Ultimate


and Premium editions of Visual Studio 2012
What is Found? What is Not Found?
• Renamed Identifiers • Type declarations are not
• Insert and delete compared
statements added • Analyze Solution for Code
• Rearranged statements Clones will not find clones
that are less than 10
statements long. However,
you can apply Find matching
clones in solution to shorter
fragments
• InitializeComponent
methods
AUTO –
IMPLEMENTED
PROP / PROPFULL PROPERTIES

– prop
• public string Name{get; set;}

– propfull
• private string _Name;
public string Name
{
get { return _Name; }
set { _Name=value; }
}
GO TO
DEFINITION
CODE
Seeing is Believing MAP

– Visualize Code
– Point and click your way through
complex code hierarchy
SURROUND
WITH

Ctrl + K,S
LINES OF
CODE

One Job for One Method

– There should be only one job for one


method
– Ideally, seven to thirty lines of code in
one method
DISPLAY NUMER
Tools -> Options -> Text Editor -> OF LINES

All Languages -> Line Numbers


ALL IN ONE
CODE
FRAMEWORK

Group related code together

– Code related to one


instance should be
together
– E.g. properties related
to one TextBlock
should be together
GO TO SPECIFIC
LINE NUMBER

Ctrl + g

– Specify the line number


– You will be jumped to that line
automatically
PASCAL CASE
TYPING

Pascal Case Methods

– Type initials of every pascal case


methods
– E.g. BookAnotherFlight will be
accessible by BAF
METHOD
NAMING

Noun-Verb Convention

– Use verbs or verb cases to name


methods
– Verbs describe the action
– Use Pascal Case
• RemoveAll()
• GetCharArray()
• GroupedItem()
METHOD
CHAINING

Invoke Multiple Method Calls

– Core concept behind it is to allow for


better readability
– Reduces the amount of code
OFFLINE
HELP

Offline Help Content

– Help ->
– Set Help Preferences ->
– Launch in Help Viewer

– Help -> View Help


ALT +
HIGHLIGHT

Highlight text vertically


COMMENT
CODE BLOCK

Comment Chunks of Code

– COMMENT:
• Ctrl + KC

– UNCOMMENT:
• Ctrl + KU

– /// <summary>
USE PHYSICAL
KEYBOARD ON
EMULATOR

Page up / page
down Key
Equals(object);
GetHashCode();

OBJECT Class
GetType();
ToString();

– Ultimate base class of all classes, all classes derived from it


(parent class of every other class)
– Inheritance not required to be declared as it is implicit.
– FOUR methods of OBJECT class available by default in a class’s
object
• Equals(Object) – Determines whether the specified object is
equal to the current object.
• GetHashCode() – Generates a number corresponding to the
value of the object to support the use of a hash table.
• GetType() – Gets the Type of the current instance.
• ToString() – Returns a string that represents the current
object.

Вам также может понравиться