Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8908747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:15:44+00:00 2026-06-15T03:15:44+00:00

The function below returns a type of Dynamic, what is the most efficient way

  • 0

The function below returns a type of Dynamic, what is the most efficient way to cast it to IDictionary

 public dynamic GetEntities(string entityName, string entityField)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:15:46+00:00Added an answer on June 15, 2026 at 3:15 am

    I’d probably go with the as operator.

    var result = GetEntities("blah", "blahblah") as IDictionary<string,string>;
    

    Then do a null check.

    UPDATE

    In regards to the “efficient” part of your question, I think as may be pretty efficient compared to some other paths you could take:

    1. You could just blindly cast it to IDictionary<string,string> and
      then catch the exception, but using exceptions for control flow
      isn’t a good idea and is expensive.
    2. You could use a convention like expression is type ? (type)expression : (type)null, but in this case, you evaluate
      expression twice (but you do get a null if the expected type isn’t
      the type that expression returns). So you’re doing double
      evaluations.
    3. as is only good for reference or boxing conversions, not to perform user-defined conversions, so if you need that, then as
      isn’t for you.

    See this article on MSDN.

    UPDATE 2

    I made an assumption on the key/value types of the IDictionary. You could just use IDictionary after as instead of specifying the generic type parameters. I guess it depends on what you’re expecting.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some question on java basics, the below function returns an object of Node type
I have function as below . public static object getClassInstance(string key, object constructorParameter) {
How is this possible that the str_replace() function below returns biWeekly and not Every
My function below calls a partial view after a user enters a filter-by string
The below function returns all the rows in Files table even when the where
I have the below function defined that passes a dynamic id to the function
The function below returns an array of XML files from a given directory including
Lets say we've got a function like f below, that returns a monad. However,
I need a function that can return the difference between the below two dates
In the below code how does passing bar as function (n) { return n;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.