is there a way in C# to rename System.Console.WriteLine so that in my C#/console/visual studio program I could write
printf("hello");
//instead of
System.Console.WriteLine("Hello"); //??
What would this be, a class? a namespace? Do I do this in the header or inside of main?
Your target looks strange and there is no way to do this in c#. Alternatively you can add a method in a class and use it.
Note: above method works only in the class which you write the above method.
First of all , do this is not a good practice.
But programatically this is achievable by wrting Wraps.
If you want to get fancy you can do this:
Then it would become:
And so on. I don't recommend this for production code - but I do use this for my test code. I'm lazy.
You can use code snippets: http://msdn.microsoft.com/en-us/library/ms165392.aspx You can always write your own.
I think Visual Studio has a few by default, like writing
cw
and hittingTAB
to getSystem.Console.WriteLine
Edit Here is a list of the default VS code snippets: http://msdn.microsoft.com/en-us/library/z41h7fat(v=vs.90).aspx
You can also use ReSharper to easily write your own, like this one I did for
dw
->Debug.WriteLine
Write a wrapper:
C# 6.0 Simplifies this by using static directives. Now instead of typing all of this:
System.Console.WriteLine(...)
, you could simply type:WriteLine(...)
More Info: C# : How C# 6.0 Simplifies, Clarifies and Condenses Your Code