---
title: "what is managed way to use a variable's pointer in structure?"  
description: "what is managed way to use a variable's pointer in structure?"  
author: "Anonymous User"  
published: 2014-11-03  
updated: 2014-11-04  
canonical: https://www.mindstick.com/forum/2503/what-is-managed-way-to-use-a-variable-s-pointer-in-structure  
category: "c#"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# what is managed way to use a variable's pointer in structure?

Hi Guys

i'm [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to write a generic [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) which should be able to [parse](https://www.mindstick.com/forum/12870/how-to-parse-json-array-using-newtonsoft) a [xml file](https://www.mindstick.com/forum/360/how-to-read-xml-file-in-php)

here is the [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii)

```
        public struct XmlArg        {            public string Name;            public Type T;            public object Value;        };         static bool ParseXmlArgs(XmlReader xml, params XmlArg[] args)        {            for (int i = 0; i < args.Length; ++i)            {                if (xml.MoveToContent() != XmlNodeType.Element || xml.Name != args[i].Name)                {                    return false;                }                args[i].Value = xml.ReadElementContentAs(args[i].T, null);            }            return true;        }         static void Main(string[] args)        {            int a = 0;             ParseXmlArgs(                XmlTextReader.Create("C:\\Users\\Yazilim\\Desktop\\XML.xml"),                new XmlArg[]{            new XmlArg() { Name = "ErrorCode", T = typeof(int), Value = a}});        }
```

i know that i should pass a's [pointer](https://www.mindstick.com/articles/11/pointers) to [Value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) ( it's type should be some different type other than object of course )

but i don't want it to be non-[managed](https://www.mindstick.com/forum/33928/what-is-managed-or-unmanaged-code-in-c-sharp) way.

is there any managed way to use a [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation)'s pointer in [structure](https://www.mindstick.com/articles/23258/choose-your-business-structure-wisely) ?

Thanks

## Replies

### Reply by Anonymous User

create an array, pass it to a method, and then read its contents afterwards:

You need to construct the XmlArg[] array before calling the method, and forget about the a variable until the parsing if finished:

```
var reader = XmlTextReader.Create("C:\\Users\\Yazilim\\Desktop\\XML.xml");
var results = new []
{
    new XmlArg() { Name = "ErrorCode", T = typeof(int) },
    new XmlArg() { Name = "ErrorMessage", T = typeof(string) }
};

if (ParseXmlArgs(reader, results) == true)
{
    // results were passed by reference, so do something with these values
}
```


---

Original Source: https://www.mindstick.com/forum/2503/what-is-managed-way-to-use-a-variable-s-pointer-in-structure

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
