web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

use of as keyword

(0) ShareShare
ReportReport
Posted on by 30

Dear All,

i read in blogs but not understand the purpose of use "as" keyword.

In standard code in SSRS reports i saw keyword "as".

Can you please let me know when and why we use "As" keyword.

What is does practically?

Please give me more shed on this.

Thanks!

Arpan

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Koen Roks Profile Picture
    on at

    Hi Arpan,

    The "as" keyword can be used for casting. When we use a common buffer we can cast it to as specific table like the "custTable"

    Another use of casting is up or down casting of class that use enheritance. For example if class Bar extends Foo you can always cast Foo back to Bar with the "as" keyword.

    Kind regards,

    Koen

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    as keyword is helpful to make downcast assignments explicit(For class or table inheritance) and is keyword on other hand helps to test whether this downcast is valid or not at run time.

    Refer following link for detailed explanation:

    (Expression Operators: Is and As for Inheritance [AX 2012])

    msdn.microsoft.com/.../gg843452.aspx;MSPPError=-2147217396

    (X++ Keywords [AX 2012])

    msdn.microsoft.com/.../aa661012.aspx

  • @rp@n Profile Picture
    30 on at

    Thanks koen and Chaitanya

    Sorry, not understand

    Example :

    AssetBalanceReportColumnsContract  contract = this.parmDataContratc() as AssetBalanceReportColumnsContract

    Can you please let me explain based on above code which using as keyword in SSRS report.

    why? what is does practically ?

    Please give me more shed on this.

    Thanks!

    Arpan

  • Suggested answer
    Mahmoud Hakim Profile Picture
    17,887 on at

    Needed when you assign a base class variable to a derived class variable. For example, given a Derived class that extends a Base class, the statement myDerived = myBase as Derived; avoids a compiler error by using the as keyword. This keyword also applies when you assign a base table variable to a derived table variable.

  • @rp@n Profile Picture
    30 on at

    Thanks Hakim,

    I understand, but what is the benefit of this ?

    myDerived = myBase as Derived

    without using "as" we can do right?

    Please give me more shed on this.

    Arpan

  • Rohin Profile Picture
    4,624 on at

    Like above shared MSDN document clearly explains why we use "AS" keyword, Let me re-write here again:

    "The as keyword tells other programmers and the compiler that you believe the downcast will be valid during run time."

     I think you should give your time to read this

  • Suggested answer
    Mahmoud Hakim Profile Picture
    17,887 on at

    can you check this link

    msdn.microsoft.com/.../gg843452.aspx

    You can use the as keyword for assignments that downcast from a base class variable to a derived class variable. The as keyword tells other programmers and the compiler that you believe the downcast will be valid during run time.

  • @rp@n Profile Picture
    30 on at

    I go through  link before krishhdax.blogspot.in/.../is-and-as-keywords-introduced-in-ax2012.html

    but not understand of meaning "Downcast".

    please give me more shed on this.

    Arpan

  • Martin Dráb Profile Picture
    237,961 Most Valuable Professional on at

    You're forgetting that you have the whole internet within arm's reach. For example, you can read about downcasting on Wikipedia.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans