C# Syntax Help
-
In the following code snippet notice the bold area. I have seen things like that quite often but not really sure how/when and why we need to use them
if (HttpContext.Current != null)
{
_Template = (BaseTemplate)LoadControl(Common.GetSkinTemplate());
Control Control;
while (this.Controls[0].Controls.Count > 0)
{
Control = this.Controls[0].Controls[0];
_Template.Content.Controls.Add(Control);
CheckForValidators(Control);
}this.Controls\[0\].Controls.Add(\_Template); }
or something like
Type myType = (MyType)Something;
can someone here please explain this? Thanks.:confused: -
In the following code snippet notice the bold area. I have seen things like that quite often but not really sure how/when and why we need to use them
if (HttpContext.Current != null)
{
_Template = (BaseTemplate)LoadControl(Common.GetSkinTemplate());
Control Control;
while (this.Controls[0].Controls.Count > 0)
{
Control = this.Controls[0].Controls[0];
_Template.Content.Controls.Add(Control);
CheckForValidators(Control);
}this.Controls\[0\].Controls.Add(\_Template); }
or something like
Type myType = (MyType)Something;
can someone here please explain this? Thanks.:confused:It's a type cast. The LoadControl method returns a value of the base type Control. To access the specific members of the template, you have to tell the compiler that it's a template, not just any control. The syntax can also be used to unbox value types that has been boxed inside an object. Example: int a = 42; object b = a; int c = (int)b; --- b { font-weight: normal; }
-
It's a type cast. The LoadControl method returns a value of the base type Control. To access the specific members of the template, you have to tell the compiler that it's a template, not just any control. The syntax can also be used to unbox value types that has been boxed inside an object. Example: int a = 42; object b = a; int c = (int)b; --- b { font-weight: normal; }
Thanks a lot :)
-
In the following code snippet notice the bold area. I have seen things like that quite often but not really sure how/when and why we need to use them
if (HttpContext.Current != null)
{
_Template = (BaseTemplate)LoadControl(Common.GetSkinTemplate());
Control Control;
while (this.Controls[0].Controls.Count > 0)
{
Control = this.Controls[0].Controls[0];
_Template.Content.Controls.Add(Control);
CheckForValidators(Control);
}this.Controls\[0\].Controls.Add(\_Template); }
or something like
Type myType = (MyType)Something;
can someone here please explain this? Thanks.:confused:think of it like chaning the window InterfaceA has method1 InterfaceB has methodA, methodB Class A has methodA and methodB casting into interfaceA will only see methodA interfaceA IA = (interfaceA)ClassA; interfaceB IB = (interfaceB)ClassA; Nick 1 line of code equals many bugs. So don't write any!!