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

  • Home
  • SEARCH
  • 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 93827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:24:20+00:00 2026-05-10T23:24:20+00:00

What are the advantages of replacing (int)reader[0] with reader.GetInt32(0) ? I’m sure such casting

  • 0

What are the advantages of replacing (int)reader[0] with reader.GetInt32(0)? I’m sure such casting functions are there for a reason, but other than it feeling more aesthetically pleasing to avoid the cast myself, I’m not sure what those reasons are.

  • 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. 2026-05-10T23:24:20+00:00Added an answer on May 10, 2026 at 11:24 pm

    In code….

            void OneWay()         {             System.Data.SqlClient.SqlDataReader reader = null;             int i = reader.GetInt32(0);         }          void OtherWay()         {             System.Data.SqlClient.SqlDataReader reader = null;             int i = (int)reader[0];         } 

    In IL

    .method private hidebysig instance void OneWay() cil managed {     .maxstack 2     .locals init (         [0] class [System.Data]System.Data.SqlClient.SqlDataReader reader,         [1] int32 i)     L_0000: nop      L_0001: ldnull      L_0002: stloc.0      L_0003: ldloc.0      L_0004: ldc.i4.0      L_0005: callvirt instance int32 [System.Data]System.Data.Common.DbDataReader::GetInt32(int32)     L_000a: stloc.1      L_000b: ret  }   .method private hidebysig instance void OtherWay() cil managed {     .maxstack 2     .locals init (         [0] class [System.Data]System.Data.SqlClient.SqlDataReader reader,         [1] int32 i)     L_0000: nop      L_0001: ldnull      L_0002: stloc.0      L_0003: ldloc.0      L_0004: ldc.i4.0      L_0005: callvirt instance object [System.Data]System.Data.Common.DbDataReader::get_Item(int32)     L_000a: unbox.any int32     L_000f: stloc.1      L_0010: ret  } 

    So, the IL is different, but I doubt that there is any noticeable difference between them. Maybe after a million iterations you will see the difference, but not likely.

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

Sidebar

Related Questions

What advantages does SQLServer CLR offer over T-SQL? Is using .NET syntax easier than
Are there any advantages compiling for .NET Framework 3.5 instead of 2.0? For example
What are the advantages/disadvantages of keeping SQL in your C# source code or in
What are the advantages/disadvantages between MS VS C++ 6.0 and MSVS C++ 2008? The
What are the advantages and disadvantages of turning NOCOUNT off in SQL server queries?
What are the advantages and disadvantages of the Session Façade Core J2EE Pattern? What
What are the advantages and disadvantages of DTOs from a website performance perspective? (I'm
What are the advantages and limitations of dynamic type languages compared to static type
One of the biggest advantages of object-oriented programming is encapsulation, and one of the
Recently I tried compiling program something like this with GCC: int f(int i){ if(i<0){

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.