I have researched this for a few hours and I am kind of frustrated. Maybe I am just missing something as I am new to blogging.
I am not hosting my own blog, I am just using WordPress.com. I want to include snippets of c# code and have them look like they do in Visual Studio, or at least make them look nice, certainly with line numbers and color. The solutions I have seen for this all seem to assume you are hosting your own blog. I cannot figure out how to install plugins.
Is there a widget that will make code snippets look nice, or some other solution I can easily use?
Thank you
EDIT: Sarfraz has outlined one way to solve my problem (thank you!), and I have tried it but there is an issue I have, namely that it does not colorize most of my code (newer keywords like var, from, where, select, etc). Is there a fix to this or is there some other solution?
Example 1: C OutputThe printf() is a library function to send formatted output to the screen. The function prints the string inside quotations. To use printf() in our program, we need to include stdio. h header file using the #include <stdio.
The %s means, "insert the first argument, a string, right here." The %d indicates that the second argument (an integer) should be placed there. There are different %-codes for different variable types, as well as options to limit the length of the variables and whatnot. Control Character.
Just edit your aricles in html mode and enclose your code within these tags.
[sourcecode language="css"] [/sourcecode]
Example:
[sourcecode language="javascript"] // javascript hello world program alert('Hello, World !!'); [/sourcecode]
Note: You need to specify correct language identifier for the language
attribute as shown above.
More Information Here :)
The [sourcecode] tag usually works fine for C#, but for me it often breaks when I post XAML code.
Instead I use this page to format my code. The result looks nice (you can see it on my blog), but it requires the "Custom CSS" option ($15/year).
EDIT: actually the [sourcecode] tag works fine, and I'm now using it in all my posts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With