Click here to Skip to main content
15,905,229 members
Home / Discussions / C#
   

C#

 
GeneralRe: Pointer in C# [modified] Pin
Thomas Weller25-Nov-08 23:45
Thomas Weller25-Nov-08 23:45 
GeneralRe: Pointer in C# Pin
Alan Balkany26-Nov-08 4:09
Alan Balkany26-Nov-08 4:09 
AnswerRe: Pointer in C# Pin
Christian Graus25-Nov-08 22:53
protectorChristian Graus25-Nov-08 22:53 
GeneralRe: Pointer in C# Pin
HosamAly25-Nov-08 23:58
HosamAly25-Nov-08 23:58 
GeneralRe: Pointer in C# Pin
Thomas Weller26-Nov-08 0:12
Thomas Weller26-Nov-08 0:12 
GeneralRe: Pointer in C# Pin
HosamAly26-Nov-08 0:29
HosamAly26-Nov-08 0:29 
GeneralRe: Pointer in C# Pin
N a v a n e e t h26-Nov-08 0:48
N a v a n e e t h26-Nov-08 0:48 
AnswerRe: Pointer in C# Pin
Simon P Stevens25-Nov-08 22:54
Simon P Stevens25-Nov-08 22:54 
I agree with Thomas. This is rather ugly design, and totally against all the principles of OO.

There are pointers in C#, you just have to use the unsafe[^] keyword before you use them. (And like Thomas say, for good reason, they are not encouraged and can cause lots of problems)

In C# types fall into two categories. Value types (structs) and reference types (classes). Reference types are kind of like pointers, when you pass them around, only the reference to the type is passed around and stored on the stack. The actual type is stored once in the heap.

You could do this:
public class AClass
{
    private BClass _b;

    public AClass(BClass b)
    {
        _b = b;
    }

    public void SomeFunc()
    {
        _b.X = 20;
    }
}

public class BClass
{
    private int _x;
    private AClass _a;

    public BClass()
    {
        _a = new AClass(this);
    }

    public int X
    {
        get
        {
            return _x;
        }
        set
        {
            _x = value;
        }
    }
}
Here, class A holds a reference to the instance of class B, so can call the public property on class B to get/set the value of B's variable.

Simon

GeneralRe: Pointer in C# Pin
Hamed Musavi25-Nov-08 23:13
Hamed Musavi25-Nov-08 23:13 
AnswerRe: Pointer in C# Pin
Shyam Bharath26-Nov-08 0:31
Shyam Bharath26-Nov-08 0:31 
GeneralRe: Pointer in C# Pin
Hamed Musavi26-Nov-08 0:46
Hamed Musavi26-Nov-08 0:46 
AnswerRe: Pointer in C# Pin
Alan Balkany26-Nov-08 4:15
Alan Balkany26-Nov-08 4:15 
Questionhelp... backup directory... any idea/class? Pin
leeoze25-Nov-08 21:41
leeoze25-Nov-08 21:41 
AnswerRe: help... backup directory... any idea/class? Pin
Christian Graus25-Nov-08 22:23
protectorChristian Graus25-Nov-08 22:23 
AnswerRe: help... backup directory... any idea/class? Pin
Christian Graus25-Nov-08 22:48
protectorChristian Graus25-Nov-08 22:48 
AnswerRe: help... backup directory... any idea/class? Pin
Simon P Stevens25-Nov-08 23:03
Simon P Stevens25-Nov-08 23:03 
AnswerRe: help... backup directory... any idea/class? Pin
Alan Balkany26-Nov-08 4:24
Alan Balkany26-Nov-08 4:24 
GeneralRe: help... backup directory... any idea/class? Pin
leeoze26-Nov-08 20:11
leeoze26-Nov-08 20:11 
QuestionPlease I really need your help Pin
Tiunay25-Nov-08 21:32
Tiunay25-Nov-08 21:32 
AnswerRe: Please I really need your help Pin
Thomas Weller25-Nov-08 21:42
Thomas Weller25-Nov-08 21:42 
GeneralRe: Please I really need your help [modified] Pin
Tiunay25-Nov-08 22:17
Tiunay25-Nov-08 22:17 
AnswerRe: Please I really need your help Pin
Christian Graus25-Nov-08 22:16
protectorChristian Graus25-Nov-08 22:16 
GeneralRe: Please I really need your help Pin
Tiunay25-Nov-08 22:21
Tiunay25-Nov-08 22:21 
QuestionDisplay different ToolTip message in different parts of the same DataGridView control Pin
Desmond Lim25-Nov-08 21:15
Desmond Lim25-Nov-08 21:15 
Questionadd-in using c# Pin
Maverickcool25-Nov-08 21:02
Maverickcool25-Nov-08 21:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.