C# SharePoint related questions
Posted on 2013-10-24
My C# understanding of the subtleties is still not very complete, and I have the following questions
Here is my code
public class BasicWebPart : WebPart
protected override void CreateChildControls()
var literal = new LiteralControl(@"<p>Some Text Here</p>");
This works. But this also works
var literal = new LiteralControl();
literal.Text = "<P>Some Text Here</p>";
Is the first the right way to do it simply because it can be done in one line of code? Any other reasons for doing it the first way instead of the second way?
And what is the significance of the @ ?. I have read that it is used to stop escapes, but why does this need to stop escapes for <p></p>? This is a webpart and it will be viewed in the browser. Does that have something to do with it? If so, why didn't I need it when in literal.Text?
I have a few other little C# questions, but I wanted to split them out. Thanks.