Code Shortcuts in Visual Studio 2010
This Article will help in writing the code in Visual Studio .Net. By using this article the programmers can use the shortcuts while writing the code and can save their time and effort to remembering all the syntax's. This article contains all the shortcuts available in the Visual Studio 2010(latest version). Find the Code Shortcuts in Visual Studio 2010
Learn Code Shortcuts in Visual Studio 2010
Hai Friends,
Since many days, I was thinking about an article or the resource which should have all the shortcuts for writing the code in Visual Studio .Net.
Then Today I thought it's better to write it by own and include all the shortcuts which are available in the Latest Version of Visual Studio (Visual Studio 2010).
Because this will help to all the programmers and whenever they want, they can go through these code snippet shortcuts to avoid the struggling of correct syntax.
Then I searched what all the shortcuts are available in the latest Visual Studio version 2010 and listed so that they can be useful to all the peoples who are using Visual Studio for their development environment.
1. To define a Destructor~ + tab tab
Code snippet:
~_Default()
{
}
2. To create an Attributeattribute + tab tab
Code snippet:
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
sealed class MyAttribute : Attribute
{
// See the attribute guidelines at
// http://go.microsoft.com/fwlink/?LinkId=85236
readonly string positionalString;
// This is a positional argument
public MyAttribute(string positionalString)
{
this.positionalString = positionalString;
// TODO: Implement code here
throw new NotImplementedException();
}
public string PositionalString
{
get { return positionalString; }
}
// This is a named argument
public int NamedInt { get; set; }
}
3. Checked keywordchecked + tab tab
Code snippet:
checked
{
}
4. Creating a Classclass + tab tab
Code snippet:
class MyClass
{
}
5. Creating a Constructorctor + tab tab
Code snippet:
public _Default()
{ }
6. Console.WriteLine() shortcutcw + tab tab
Code snippet:
Console.WriteLine ();
7. Do…..while loopdo + tab tab
Code snippet:
do
{
} while (true);
8. Else statementelse + tab tab
Code snippet:
else
{}
9. Enumenum + tab tab
Code snippet:
enum MyEnum
{
}
10. Equalsequals +tab tab
Code snippet:
// override object.Equals
public override bool Equals(object obj)
{
//
// See the full list of guidelines at
// http://go.microsoft.com/fwlink/?LinkID=85237
// and also the guidance for operator== at
// http://go.microsoft.com/fwlink/?LinkId=85238
//
if (obj == null || GetType() != obj.GetType())
{
return false;
}
// TODO: write your implementation of Equals() here
throw new NotImplementedException();
return base.Equals(obj);
}
// override object.GetHashCode
public override int GetHashCode()
{
// TODO: write your implementation of GetHashCode() here
throw new NotImplementedException();
return base.GetHashCode();
}
11. Exceptionsexceptions + tab tab
Code snippet:
[Serializable]
public class MyException : Exception
{
public MyException() { }
public MyException(string message) : base(message) { }
public MyException(string message, Exception inner) : base(message, inner)
}
protected MyException
(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
12. For loopfor + tab tab
Code snippet:
for (int i = 0; i < length; i++)
{
}
13. Foreach loopforeach + tab tab
Code snippet:
foreach (var item in collection)
{
}
14. Reverse for loopfor + tab tab
Code snippet:
for (int i = length - 1; i >= 0 ; i--)
{
}
15. If statementif + tab tab
Code snippet:
if (true)
{
}
16. Indexerindexer + tab tab
Code snippet:
public object this[int index]
{
get { /* return the specified index here */ }
set { /* set the specified index to value here */ }
}
17. Interfaceinterface + tab + tab
Code snippet:
interface IInterface
{
}
18. Invoke- to safely invoke the eventinvoke + tab tab
Code snippet:
EventHandler temp = MyEvent;
if (temp != null)
{
temp();
}
19. Iterator- simple iteratoriterator + tab tab
Code snippet:
public System.Collections.Generic.IEnumerator
{
throw new NotImplementedException();
yield return default(ElementType);
}
20. Iterator – complex iteratoriterindex + tab tab
Code snippet:
public MyViewIterator MyView
{
get
{
return new MyViewIterator(this);
}
}
public class MyViewIterator
{
readonly _Default outer;
internal MyViewIterator(_Default outer)
{
this.outer = outer;
}
// TODO: provide an appropriate implementation here
public int Length { get { return 1; } }
public ElementType this[int index]
{
get
{
//
// TODO: implement indexer here
//
// you have full access to _Default privates
//
throw new NotImplementedException();
return default(ElementType);
}
}
public System.Collections.Generic.IEnumerator
{
for (int i = 0; i < this.Length; i++)
{
yield return this[i];
}
}
}
21. Lock statementlock + tab tab
Code snippet:
lock (this)
{}
22. To Show the Message box in ASP.Net/Console Applicationmbox + tab tab
Code snippet:
global::System.Windows.Forms.MessageBox.Show("hello");
23. Actionmvcaction +tab tab
Code snippet:
public ActionResult Action()
{
return View();
}
24. Action via http post methodmvcpostaction + tab tab
Code snippet:
[HttpPost]
public ActionResult Action()
{
return View();
}
25. For Namespacenamespace + tab tab
Code snippet:
namespace MyNamespace
{
}
26. Creating Propertyprop + tab tab
Code snippet:
public int MyProperty { get; set; }
27. Attached dependency propertypropa + tab tab
Code snippet:
public static int GetMyProperty(DependencyObject obj)
{
return (int)obj.GetValue(MyPropertyProperty);
}
public static void SetMyProperty(DependencyObject obj, int value)
{
obj.SetValue(MyPropertyProperty, value);
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.RegisterAttached("MyProperty", typeof(int), typeof(ownerclass), new UIPropertyMetadata(0));
28. Dependency property as a backing storepropdp + tab tab
Code snippet:
public int MyProperty
{
get { return (int)GetValue(MyPropertyProperty); }
set { SetValue(MyPropertyProperty, value); }
}
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc...
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(int), typeof(ownerclass), new UIPropertyMetadata(0));
29. Property with full descriptionpropfull + tab tab
Code snippet:
private int myVar;
public int MyProperty
{
get { return myVar;}
set { myVar = value;}
}
30. Auto implemented property with get accessor as privatepropg + tab tab
Code snippet:
public int MyProperty { get; set; }
31. For int Main methodsim + tab tab
Code snippet:
static int Main(string[] args)
{
return 0;
}
32. Create structurestruct + tab tab
Code snippet:
struct MyStruct
{
}
33. Void Main methodsvm + tab tab
Code snippet:
static void Main(string[] args)
{}
34. Switch stamenswitch + tab tab
Code snippet:
switch (switch_on)
{
default:
}
35. Test classtestc + tab tab
Code snippet:
[global::Microsoft.VisualStudio.TestTools.UnitTesting.TestClass]
public class MyTestClass
{
}
36. Test methodtestm + tab tab
Code snippet:
[global::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethod]
public void MyTestMethod()
{
}
37. Try..catchtry + tab tab
Code snippet:
try
{}
catch (Exception)
{
throw;
}
38. Try..finallytryf + tab tab
Code snippet:
try
{}
catch (Exception)
{
throw;
}
39. Unchecked statementunchecked + tab tab
Code snippet:
unchecked
{
}
40. Unsafe statementunsafe + tab tab
Code snippet:
unsafe
{
}
41. Using statementusing + tab tab
Code snippet:
using (resource)
{
}
42. Dependency property event handler in windows work flow applicationwde + tab tab
Code snippet:
public static global::System.Workflow.ComponentModel.DependencyProperty InvokeEvent = global::System.Workflow.ComponentModel.DependencyProperty.Register("Invoke", typeof(EventHandler), typeof(_Default));
[System.ComponentModel.Description("Invoke")]
[System.ComponentModel.Category("Invoke Category")]
[System.ComponentModel.Browsable(true)]
[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Visible)]
public event EventHandler Invoke
{
add
{
base.AddHandler(_Default.InvokeEvent, value);
}
remove
{
base.RemoveHandler(_Default.InvokeEvent, value);
}
}
43. Dependency property in windows work-flow applicationwdp + tab tab
Code snippet:
public static global::System.Workflow.ComponentModel.DependencyProperty MyPropertyProperty = global::System.Workflow.ComponentModel.DependencyProperty.Register("MyProperty", typeof(string), typeof(_Default));
[System.ComponentModel.Description("MyProperty")]
[System.ComponentModel.Category("MyProperty Category")]
[System.ComponentModel.Browsable(true)]
System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Visible)]
public string MyProperty
{
get
{
return ((string)(base.GetValue(_Default.MyPropertyProperty)));
}
set
{
base.SetValue(_Default.MyPropertyProperty, value);
}
}
44. While loopwhile + tab tab
Code snippet:
while (true)
{
}
Wow....!
Great work !