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 152311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:36:02+00:00 2026-05-11T09:36:02+00:00

I understand pointers and the rare need to use them in C# code. My

  • 0

I understand pointers and the rare need to use them in C# code. My question is: what is the reasoning behind having to explicitly state ‘unsafe’ in a block of code. Additionally, why must a compiler option be changed to allow ‘unsafe’ code?

Bottom Line: What in the CLR (or language specs) makes it so we can’t just use pointers whenever we want (much like C and C++) without having to type ‘unsafe’ and change the compiler option?

For clarification: I know what ‘unsafe’ and ‘safe’ code is. It’s just a question of why must we do all the extra work (ok, not THAT much extra) just to be able to use these features.

  • 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-11T09:36:02+00:00Added an answer on May 11, 2026 at 9:36 am

    There’s an interview with C# Creator Anders Hejlsberg that touches on the subject here. Basically, exactly what @Marc Gravell said: typesafety first, unsafety by explicit declaration.

    So to answer your question: nothing in the CLR prevents it; it’s a language idiom designed to allow you to work with safety gloves when dealing with types. If you want to take the gloves off, it’s your choice, but you have to make the active choice to take the gloves off.

    Edit:

    For clarification: I know what ‘unsafe’ and ‘safe’ code is. It’s just a question of why must we do all the extra work (ok, not THAT much extra) just to be able to use these features.

    As mentioned in the interview I linked, it was an explicit design decision. C# is essentially an evolution of Java and in Java, you don’t have pointers at all. But the designers wanted to allow pointers; however because C# would typically be bringing in Java developers, they felt it would be best if the default behavior be similar to Java, i.e. no pointers, while still allowing the use of pointers by explicit declaration.

    So the ‘extra work’ is deliberate to force you to think about what you are doing before you do it. By being explicit, it forces you to at least consider: ‘Why am I doing this? Do I really need a pointer when a reference type will suffice?’

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

Sidebar

Ask A Question

Stats

  • Questions 312k
  • Answers 312k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Check the ParameterInfo instance's optional custom modifiers: bool IsLongParameter(System.Reflection.ParameterInfo p)… May 13, 2026 at 10:36 pm
  • Editorial Team
    Editorial Team added an answer I agree with David in that using a MD5 hash… May 13, 2026 at 10:36 pm
  • Editorial Team
    Editorial Team added an answer Sorry for the late but it may help some people… May 13, 2026 at 10:36 pm

Related Questions

I understand the overall meaning of pointers and references(or at least I think i
I am learning about pointers and one concept is troubling me. I understand that
I'm having trouble understanding the following bit of code that I was hoping would
I'm sort of learning C, I'm not a beginner to programming though, I know

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.