I am new to .Net C# coding. I have my aspx.cs file reading in an XML File and I want to use this data to create a chart in a silverlight application which is part of the same project but the aspx c# website and silverlight application have different namespaces. How can I send my XML read in data to silverlight applicat开发者_运维技巧ion in the same project but different namespace?
The namespace does not present any data boundary; it is simply just a part of the name. So if you have a class defined in your project like so:
namespace Some.Namespace
{
class FirstClass
{
string SomeValue { get; set; }
}
}
...and then want to use this class within another class in a different namespace in the same project, you just need to refer to FirstClass
using the namespace:
namespace Some.Other.Namespace
{
class SecondClass
{
void SomeMethod()
{
Some.Namespace.FirstClass temp = new Some.Namespace.FirstClass();
temp.SomeValue = "test";
}
}
}
One alternative, which will make your code a bit more brief is to add a using
directive in the code file for SecondClass
, which enables you to refer to FirstClass
without including the namespace each time:
using Some.Namespace;
namespace Some.Other.Namespace
{
class SecondClass
{
void SomeMethod()
{
// note how the namespace is not needed here:
FirstClass temp = new FirstClass();
temp.SomeValue = "test";
}
}
}
This means that if you have a class that handles accessing the xml file, and that is located in some namespace of your project, you should be able use that same class both in the aspx page and the silverlight application.
精彩评论