dcsimg
Results 1 to 4 of 4

Thread: [RESOLVED] Ref int unsafe code in C#

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2016
    Posts
    143

    Resolved [RESOLVED] Ref int unsafe code in C#

    I come across some C# codes as C++'s pointer. But I never used such technique. Please explain how it works.

    ref int val2 = ref this.intCounts;
    ref reference = ref val2;
    val2 = reference + 1;
    it seems to be this.intCounts++. Does .NET 2.0 supports above codes?

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    101,594

    Re: Ref int unsafe code in C#

    Quote Originally Posted by DaveDavis View Post
    Please explain how it works.
    The explanation is in the documentation, which is the first place you should always look. VS has a Help menu for a reason.

    https://docs.microsoft.com/en-us/dot...-return-values
    Quote Originally Posted by DaveDavis View Post
    Does .NET 2.0 supports above codes?
    It's got nothing to do with the .NET Framework version because it's not a .NET feature. What matters is the C# version because this is a C# language feature. I don't know what version of C# this feature was introduced in but as long as you are using that version of C# or later, you can target any .NET version supported by that IDE.

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    101,594

    Re: Ref int unsafe code in C#

    By the way, this is not unsafe code because it's not using pointers. Pointers are actually variables that contain numeric memory addresses. That this code is using .NET references.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2016
    Posts
    143

    Re: Ref int unsafe code in C#

    Thanks jmci.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width