I want to have a constant string kURL = "http://www.myurl.com/";
throughout my entire project. What's the proper way to do this in a Windows Phone 7 app?
Where would I put this code and what should the proper syntax be?
Create a .Common project for things that you may need to access from all of your projects in your solution (like constants, extension methods, utils etc.), in there simply create Constants class with any Constants that you may need.
Like this:
public static class Constants
{
#region Nested type: Urls
public static class Urls
{
public static readonly string MyUrl = "http://blablabla.com";
}
#endregion
}
Usage would be:
Constants.Urls.MyUrl
Good luck.
Edit Note: Changed to const as per Gabes suggestion
Edit Note2: Changed to static readonly per lukas suggestion
Here is a simple tutorial on creating Global Consts in C#. I've used this for .NET, but not Windows Phone. I would assume the same conventions are followed.
http://www.dotnetperls.com/global-variable
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