What are the most useful (custom) code snippets for C#? [closed]
-
09-06-2019 - |
Question
What are the best code snippets for C#? (using visual studio) VB has a lot that are pre-defined, but there are only a handful for C#. Do you have any really useful ones for C#?
Anyone want to post a good custom one you created yourself?
Solution
Microsoft have released a whole bunch of C# snippets that bring it up to parity with the ones for Visual Basic. You can download them here:
OTHER TIPS
My absolute favorite is cw
.
There's plenty of code snippets within Visual Studio for basic programming structure but I wouldn't necessarily rate one higher than another.
I would definitely say the best ones are the custom snippets you define yourself to accomplish more specific tasks that you may find yourself using on a regular basis. Definitely a big time saver.
A fairly basic intro to creating custom snippets can be found at http://www.15seconds.com/issue/080724.htm to help with this.
I had a few on my old blog:
I also have an argnull
code snippet that inserts a Guard Clause that checks an argument for null and throws an ArgumentNullException, but I haven't gotten around to post that yet.
prop and exception are my favorites.
These are the ones I use daily.
- prop
- try
- if
- else
- for
- foreach
- mbox - Message box stub
- The ability to role your own. I have one for Property that are saved in the view state, methods a custom class example.
Just to update an older thread... here's a link for Visual Studio 2008 C# code snippet download.
I just started a blog, where I document short solutions in C# (code snippets) that I came up with and might prove useful to other coders.
http://thorstenlorenz.blogspot.com/
So far I have mostly blogged about extension methods and generics.
So have a look and tell me what you think.