0

I want to write simple macro in c#, to be more clear i just want to save some typing when testing (but want use snippets, cause they don't save space). Want to replace reserved keywords with shorter words Example in c++ (return sum):

#define r return
int foo(int i, int c){ r (i + c); }

So the point is to save same space and typing, is there something similar in c#?

8
  • If you're using Visual Studio, try typing "re" and then hit Tab. It'll save you typing (but not space). Commented Feb 28, 2014 at 9:02
  • Also i need to save some space ... Commented Feb 28, 2014 at 9:04
  • possible duplicate of C# Macro definitions in Preprocessor Commented Feb 28, 2014 at 9:06
  • No it's not possible duplicate this is different question with different needs Commented Feb 28, 2014 at 9:10
  • @tonni How is it any different? Just because you talk about return and not about Console.WriteLine? Commented Feb 28, 2014 at 9:12

1 Answer 1

3

C# does not support macros like C++. Visual Studio on the other hand has snippets

Check that question:

C# Macro definitions in Preprocessor

Macros in a different sense:

http://alookonthecode.blogspot.com.au/2011/06/macros-in-c.html

A Macro Preprocessor in C#

http://www.codeproject.com/Articles/10049/A-Macro-Preprocessor-in-C

Sign up to request clarification or add additional context in comments.

3 Comments

Snippet have to be written outside of code .... i want to do it in code with something like dictionary or else
thnx for effort but this don't change reserved keyword it is something like refactory
In that case you need to write your own preprosessor. Check that codeproject article codeproject.com/Articles/10049/A-Macro-Preprocessor-in-C

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.