string
is an alias in C# for System.String
.
So technically, there is no difference. It's like int
vs. System.Int32
.
As far as guidelines, it's generally recommended to use string
any time you're referring to an object.
e.g.
string place = "world";
Likewise, I think it's generally recommended to use String
if you need to refer specifically to the class.
e.g.
string greet = String.Format("Hello {0}!", place);
This is the style that Microsoft tends to use in their examples.
It appears that the guidance in this area may have changed, as StyleCop now enforces the use of the C# specific aliases.
Apart from the apparent difference of
- having to declare the value at the time of a definition for a
const
VS readonly
values can be computed dynamically but need to be assigned before the constructor exits.. after that it is frozen.
const
's are implicitly static
. You use a ClassName.ConstantName
notation to access them.
There is a subtle difference. Consider a class defined in AssemblyA
.
public class Const_V_Readonly
{
public const int I_CONST_VALUE = 2;
public readonly int I_RO_VALUE;
public Const_V_Readonly()
{
I_RO_VALUE = 3;
}
}
AssemblyB
references AssemblyA
and uses these values in code. When this is compiled:
- in the case of the
const
value, it is like a find-replace. The value 2 is 'baked into' the AssemblyB
's IL. This means that if tomorrow I update I_CONST_VALUE
to 20, AssemblyB
would still have 2 till I recompile it.
- in the case of the
readonly
value, it is like a ref
to a memory location. The value is not baked into AssemblyB
's IL. This means that if the memory location is updated, AssemblyB
gets the new value without recompilation. So if I_RO_VALUE
is updated to 30, you only need to build AssemblyA
and all clients do not need to be recompiled.
So if you are confident that the value of the constant won't change, use a const
.
public const int CM_IN_A_METER = 100;
But if you have a constant that may change (e.g. w.r.t. precision).. or when in doubt, use a readonly
.
public readonly float PI = 3.14;
Update: Aku needs to get a mention because he pointed this out first. Also I need to plug where I learned this: Effective C# - Bill Wagner
Best Answer
I thought I'd come back to answer this. The mobile forms controls are still there and the templates provided unofficially above are the only ones available that I've found. I'm not sure why they took them out in Visual Studio 2008.
Without the templates, you mostly you just need to change your pages to derive from MobilePage instead of Page and your controls to derive from MobileUserControl instead of UserControl. To access the controls in markup, reference the mobile namespace like this:
and then you will be able to use the mobile controls like this:
mobile:form, mobile:textview ...
These are still the only way that I've found to create pages that are compatible with older phones and browsers. Newer phones and browsers of course use standard HTML for the most part and pages can be created the same as any other ASP.Net page.