Click here to Skip to main content
15,921,643 members
Home / Discussions / C#
   

C#

 
GeneralRe: Remoting in .net Pin
Shyam Bharath26-Nov-08 0:35
Shyam Bharath26-Nov-08 0:35 
JokeRe: Remoting in .net Pin
Thomas Weller26-Nov-08 0:49
Thomas Weller26-Nov-08 0:49 
GeneralRe: Remoting in .net Pin
Shyam Bharath26-Nov-08 0:54
Shyam Bharath26-Nov-08 0:54 
QuestionPointer in C# Pin
Hamed Musavi25-Nov-08 22:26
Hamed Musavi25-Nov-08 22:26 
AnswerRe: Pointer in C# Pin
Thomas Weller25-Nov-08 22:41
Thomas Weller25-Nov-08 22:41 
GeneralRe: Pointer in C# Pin
Hamed Musavi25-Nov-08 23:06
Hamed Musavi25-Nov-08 23:06 
GeneralRe: Pointer in C# Pin
Thomas Weller25-Nov-08 23:24
Thomas Weller25-Nov-08 23:24 
GeneralRe: Pointer in C# [modified] Pin
Hamed Musavi25-Nov-08 23:38
Hamed Musavi25-Nov-08 23:38 
GeneralRe: Pointer in C# Pin
#realJSOP25-Nov-08 23:18
professional#realJSOP25-Nov-08 23:18 
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 

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.