Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. C# Syntax Help

C# Syntax Help

Scheduled Pinned Locked Moved ASP.NET
csharphelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Taurian110
    wrote on last edited by
    #1

    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:

    G I 2 Replies Last reply
    0
    • T Taurian110

      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:

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      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; }

      T 1 Reply Last reply
      0
      • G Guffa

        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; }

        T Offline
        T Offline
        Taurian110
        wrote on last edited by
        #3

        Thanks a lot :)

        1 Reply Last reply
        0
        • T Taurian110

          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:

          I Offline
          I Offline
          Ista
          wrote on last edited by
          #4

          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!!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups