开发者

What is happening when you declare an XNamespace and assign a string value?

开发者 https://www.devze.com 2023-03-30 05:17 出处:网络
Here is the example from MSDN for XNamespace: XNamespace aw = \"http://www.adventure-works.com\"; XElement root = new XElement(aw + \"Root\", \"Content\");

Here is the example from MSDN for XNamespace:

XNamespace aw = "http://www.adventure-works.com";
XElement root = new XElement(aw + "Root", "Content");
Console.WriteLine(root);

I am not sure what is 开发者_StackOverflowhappening in the first line. Is there some kind of implicit conversion going on?


XNamespace has a static Get method that accepts a string parameter and returns an XNamespace instance. So you could rewrite the line as

XNamespace aw = XNamespace.Get("http://www.adventure-works.com");

In the version you posted, you would be taking advantage of an implicit conversion defined against string. Presumably, the implementation thereof simply invokes the aforementioned method. An example of a possible implementation:

public static implicit operator XNamespace(string name)
{
    return Get(name);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号