Results 1 to 6 of 6

Thread: Can we use pointer in C#?

  1. #1
    Join Date
    Dec 2009
    Posts
    14

    Can we use pointer in C#?

    I am beginner(fresher) programmer in the uprising programming world. The programming world is growing day-by-day and new invention comes every next day. I am also learning programming language like C sharp, C++, Java, DBMS and PHP. Right now i am working in the C sharp language, i know how to use pointers in C++ , but not in C sharp. Is pointers are usable in C sharp and if yes how to implement it? Please help me on this.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Can we use pointer in C#?

    Yes, the pointers are usable in C sharp (i.e C sharp supports pointers). And you can use the pointers by using the unsafe keyword.
    Example of ponters:
    unsafe
    {
    //all the code/process related to pointers
    }
    Also note that by using pointers it your code unmanageable. Also if you want to have pointers to class level variables you must use fixed keyword. Hope your problem will be solved.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Can we use pointer in C#?

    Firstly would say that pointer's are nothing more than a variable which will hold the address in memory of another variable. And in C sharp, the pointer's can only be used on value types and arrays. In C sharp, pointers are define using the unsafe keyword. Simple example of pointers:
    static void Main(string[] args)
    {
    unsafe
    {
    int magicno= 786;
    int* magicno_ptr;
    Console.WriteLine("magic number = {0}", magicno);
    }
    }
    Hope you will understand the pointers use and your problem would be fix.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Can we use pointer in C#?

    According to me, the pointers are used or supported in C sharp. And they are considered as an unsafe code. The pointers is a variable which will hold the address in memory of another variable. You can use pointers in the similar manner as you would be using in the C++ or VC++, but only change is that in C sharp you have to build it up with the unsafe option/ unsafe keyword. Pointers are mainly used in C sharp for value and array types only. Hope your problem will be solved.
    Last edited by kelfro; 29-01-2010 at 10:36 AM.

  5. #5
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Can we use pointer in C#?

    The C sharp does not allow the pointer in the managed code. This is because, the pointer are able to point anywhere in the memory, and it will be possible to misuse a pointer. It is also easy to introduce a coding error when using pointers. Due to this all C sharp doesn't support pointers when creating managed code. But C sharp do allow you to make and use pointers. All pointer operations must be marked as unsafe, since they execute outside the managed context. Hope your problem is fixed.

  6. #6
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Can we use pointer in C#?

    I personally think that C sharp does support the pointer, but in unmanaged code , by using the unsafe keyword. Mainly pointers are used to point to the other variables memory address. The three main use of pointer are a follows
    1] It used for calling the by reference concept.
    2] By using the pointer we can work on exact memory location
    instead of other variable.
    3] It use for number of pointer's that can point to same memory address.
    Hope oyu got enough information to understand pointers in C sharp.

Similar Threads

  1. Changing Stylus pointer to normal Pointer in Tablet PC
    By Kelley in forum Portable Devices
    Replies: 3
    Last Post: 21-06-2011, 07:22 PM
  2. Deleting the same pointer twice in C++
    By KAMAL60 in forum Software Development
    Replies: 6
    Last Post: 29-06-2010, 12:02 AM
  3. Don't know about void pointer
    By Sarfaraj Khan in forum Software Development
    Replies: 5
    Last Post: 04-02-2010, 01:39 PM
  4. Differentiation between void pointer and null pointer
    By Ram Bharose in forum Software Development
    Replies: 5
    Last Post: 18-01-2010, 12:11 PM
  5. Pointer to structure in C
    By Jamaima in forum Software Development
    Replies: 3
    Last Post: 08-10-2009, 03:30 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,622,931.22643 seconds with 17 queries