473,396 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Address in C#

Please answer my following questions.
(1). How to print address of any variable in C#. for example
int x; int [] y=new int[4];
how to printf address of x and address of first element of array y.

(2)In C we could print values of any decimal number in Hex or Octal by
simply writing %h or %O. how can we do it in C#, windows programming.

(3)what is difference between safe and unsafe region.
(4)What is difference between fixed and non fixed.
(5)Can any body point me to ebook on net which cover pointers in C# in
details
Nov 17 '05 #1
6 6716
javaid iqbal <ja*******@yahoo.com> wrote:
Please answer my following questions.
(1). How to print address of any variable in C#. for example
int x; int [] y=new int[4];
how to printf address of x and address of first element of array y.
You can't in safe code; in unsafe code you can take a pointer in
roughly the same way you do in C:

int x = 10;
int* y = &x;
(2)In C we could print values of any decimal number in Hex or Octal by
simply writing %h or %O. how can we do it in C#, windows programming.
Look up "standard numeric format strings" in MSDN.
(3)what is difference between safe and unsafe region.
If you look up "unsafe code" in MSDN, there's a fairly in-depth
tutorial
(4)What is difference between fixed and non fixed.
That's covered in the above. Basically when an object is fixed, it
can't be moved by the garbage collector.
(5)Can any body point me to ebook on net which cover pointers in C# in
details


A search for unsafe and C# will find you quite a few articles. Why do
you think you need pointers, out of interest?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
Thanks Jon for quick reply.

If i do following in unsafe code.
int s;
label1.Text = &s.ToString();

I get following errors. how to fix it

D:\mysource\C Sharp\WindowsApplicationOCX\Form1.cs(236): Cannot implicitly
convert type 'string*' to 'string'
D:\mysource\C Sharp\WindowsApplicationOCX\Form1.cs(236): Cannot take the
address of the given expression
D:\mysource\C Sharp\WindowsApplicationOCX\Form1.cs(236): Cannot take the
address or size of a variable of a managed type ('string')
D:\mysource\C Sharp\WindowsApplicationOCX\Form1.cs(236): You can only take
the address of unfixed expression inside of a fixed statement initializer
Nov 17 '05 #3
Javaid,

label1.Text is a string property dealing with string references not the adress

label1.Text = n.ToString();
On Sat, 09 Jul 2005 10:27:01 +0200, javaid iqbal <ja*******@yahoo.com> wrote:
int s;
label1.Text = &s.ToString();


--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #4
Sir my question is how to print the address of integer x.

"Morten Wennevik" wrote:
Javaid,

label1.Text is a string property dealing with string references not the adress

label1.Text = n.ToString();
On Sat, 09 Jul 2005 10:27:01 +0200, javaid iqbal <ja*******@yahoo.com> wrote:
int s;
label1.Text = &s.ToString();


--
Happy coding!
Morten Wennevik [C# MVP]

Nov 17 '05 #5
javaid iqbal <ja*******@yahoo.com> wrote:
Sir my question is how to print the address of integer x.


Then you certainly don't want to be using string pointers. You can do:

using System;

class Test
{
unsafe static void Main()
{
int x = 10;
int* y = &x;
Console.WriteLine(new IntPtr(y));
}
}

I would question how useful this is though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6
Hi javaid

The meaning of &s.ToString() is: Get the string-representation of s and get
the address of it.
Try: (&s).ToString()

"javaid iqbal" <ja*******@yahoo.com> schrieb im Newsbeitrag
news:E5**********************************@microsof t.com...
Thanks Jon for quick reply.

If i do following in unsafe code.
int s;
label1.Text = &s.ToString();

I get following errors. how to fix it

D:\mysource\C Sharp\WindowsApplicationOCX\Form1.cs(236): Cannot implicitly
convert type 'string*' to 'string'
D:\mysource\C Sharp\WindowsApplicationOCX\Form1.cs(236): Cannot take the
address of the given expression
D:\mysource\C Sharp\WindowsApplicationOCX\Form1.cs(236): Cannot take the
address or size of a variable of a managed type ('string')
D:\mysource\C Sharp\WindowsApplicationOCX\Form1.cs(236): You can only take
the address of unfixed expression inside of a fixed statement initializer

Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Alexander N. Spitzer | last post by:
If I have a machine with 3 virtual IP addresses (192.168.1.), how can I start 3 instances of the same RMI application (each started with different properties/configs), each listening on the port...
8
by: YAN | last post by:
Hi, I want to get the mac address from a machine, which i have the IP address of that machine, how can i do that? I know how to get the mac address of the local machine from the following code: ...
7
by: Privacy Advocate | last post by:
//crossposted to: comp.lang.javascript, alt.comp.lang.javascript in an effort to get factual answers from JavaScript experts// Simply put; Is it possible to obtain the real (actual) IP address of...
33
by: baumann.Pan | last post by:
hi all, i want to get the address of buf, which defined as char buf = "abcde"; so can call strsep(address of buf, pointer to token);
4
by: andreas.w.h.k. :-\) | last post by:
How do I change the address location in the wsdl <wsdl:port name="SearchSoap12" binding="tns:SearchSoap12"> <soap12:address location="http://searchservices/engine/search.asmx" /> </wsdl:port> ...
1
by: Phoenix_ver10 | last post by:
I have a mailing list with multiple names going to the same addresses. I need one address with all the names for that address on it. I checked out the example on microsoft's site, but A: It doesn't...
1
by: Jamie J. Begin | last post by:
I'm very new to the world of Python and am trying to wrap my head around it's OOP model. Much of my OOP experience comes from VB.Net, which is very different. Let's say I wanted to create an...
6
by: Nicolas Noakes | last post by:
Hello, I would like to convert to following process to code. Any advice is welcome. I have a hardware device which requires the this procedure to set it's IP address. First create an static...
36
by: Julienne Walker | last post by:
Ignoring implementation details and strictly following the C99 standard in terms of semantics, is there anything fundamentally flawed with describing the use of a (non-inline) function as an...
1
by: saravanatmm | last post by:
I need javascript code for validate the email address. Email address field cannot allowed the capital letters, special characters except '@' symbol. But can allowed the small letters, numeric...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.