I've tried to find answer to this question on the net but without success,
so I hope someone here knows...
How can I know if c# actualy creates an instance of an object when I declare
a variable...
For example....
If I declare
private System.Collecti ons.ArrayList m_aArray;
Then I dont have an instance of that object
But this declaretion
private System.Guid m_testId;
acctually results in an object..
I'm from the C++ school so this is very confusing to me, thanks for the
help!
// Mikael 6 2090
"Mikael Janers" <NO************ @home.se__SPAMF ILTER> wrote in message
news:eW******** ******@tk2msftn gp13.phx.gbl... If I declare private System.Collecti ons.ArrayList m_aArray;
Then I dont have an instance of that object
But this declaretion
private System.Guid m_testId;
acctually results in an object..
System.Guid is actually a value type. You are able to treat it like an object
because C# boxes it up for you automatically.
--
Iain Simpson
Basically if the class is derived from System.ValueTyp e then declaring a
variable of that type will assign it an instance using the default
constructor (unless you specify otherwise).
System.Guid is a structure and thus derives from System.ValueTyp e.
S.
"Mikael Janers" <NO************ @home.se__SPAMF ILTER> wrote in message
news:eW******** ******@tk2msftn gp13.phx.gbl... I've tried to find answer to this question on the net but without success, so I hope someone here knows...
How can I know if c# actualy creates an instance of an object when I
declare a variable...
For example....
If I declare private System.Collecti ons.ArrayList m_aArray;
Then I dont have an instance of that object
But this declaretion
private System.Guid m_testId;
acctually results in an object..
I'm from the C++ school so this is very confusing to me, thanks for the help! // Mikael
Structs can't be derived from as they are always implicitly derived from
ValueType so it's pretty easy to tell by going to the definition or by
looking at the documentation which always postfixes the type ( class or
structure).
Regards
Lee
"Mikael Janers" <NO************ @home.se__SPAMF ILTER> wrote in message
news:eW******** ******@tk2msftn gp13.phx.gbl... I've tried to find answer to this question on the net but without success, so I hope someone here knows...
How can I know if c# actualy creates an instance of an object when I
declare a variable...
For example....
If I declare private System.Collecti ons.ArrayList m_aArray;
Then I dont have an instance of that object
But this declaretion
private System.Guid m_testId;
acctually results in an object..
I'm from the C++ school so this is very confusing to me, thanks for the help! // Mikael
Mikael Janers <NO************ @home.se__SPAMF ILTER> wrote: I've tried to find answer to this question on the net but without success, so I hope someone here knows...
How can I know if c# actualy creates an instance of an object when I declare a variable...
For example....
If I declare private System.Collecti ons.ArrayList m_aArray;
Then I dont have an instance of that object
But this declaretion
private System.Guid m_testId;
acctually results in an object..
I'm from the C++ school so this is very confusing to me, thanks for the help!
Guid is a value type. ArrayList is a reference type. In both cases, you
get a variable which has the "default value": the default value of a
reference type is null (and no instances are created); the default
value of a value type is the value which has the default value for each
variable (0, null, false etc).
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Wow, this group is realy fast =)
Thank you all for the help!
"Jon Skeet" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@news.microsof t.com... Mikael Janers <NO************ @home.se__SPAMF ILTER> wrote: I've tried to find answer to this question on the net but without
success, so I hope someone here knows...
How can I know if c# actualy creates an instance of an object when I
declare a variable...
For example....
If I declare private System.Collecti ons.ArrayList m_aArray;
Then I dont have an instance of that object
But this declaretion
private System.Guid m_testId;
acctually results in an object..
I'm from the C++ school so this is very confusing to me, thanks for the help!
Guid is a value type. ArrayList is a reference type. In both cases, you get a variable which has the "default value": the default value of a reference type is null (and no instances are created); the default value of a value type is the value which has the default value for each variable (0, null, false etc).
-- Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet/ If replying to the group, please do not mail me too
Hi Jon: Guid is a value type. ArrayList is a reference type. In both cases, you get a variable which has the "default value": the default value of a reference type is null (and no instances are created); the default value of a value type is the value which has the default value for each variable (0, null, false etc).
Value type has default value only if it is created in the managed heap (as a
part of the other type). If you create a value type in the stack, though,
the value is not defined. C# compiler won't let you use not initialized
value type created in the thread stack
In the example given by Mikael:
private System.Guid m_testId;
m_testId obvioulsy is field of the other type. If it is field of a reference
type (class) it will have default value as long it is going to be created in
the managed heap. If it is field of a value type (struct) it might have or
it might have not a default value.
B\rgds
100 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Chris Lasher |
last post by:
Hello,
I really like the finditer() method of the re module. I'm having
difficulty at the moment, however, because finditer() still creates a
callable-iterator oject, even when no match is found. This is
undesirable in cases where I would like to circumvent execution of code
meant to parse out data from my finditer() object.
I know that if I place a finditer() object in an iterative for loop,
the loop will not execute, but is there some...
|
by: Me |
last post by:
Just a question/observation out of frustration.
I read in depth the book by Peter Van Der Linden entitled
"Expert C Programming" (Deep C Secrets). In particular the
chapters entitled:
4: The Shocking Truth: C Arrays and Pointers Are NOT the Same!
9: More about Arrays
10: More about Pointers
What blows me out of the water is the fact that 'every' programmer
|
by: Jim Frazer |
last post by:
Hi,
I'm new to C#, but experienced in C++. I'm converting an ActiveX object to
C#. There is a single instance of a "primary" class which creates two
collections of other "secondary" classes. Each of these other classes needs
to access the information in the primary class - items like a mutex, an
IntPtr to a shared memory map, etc. In C++, I'd probably pass a pointer to
the primary class to each of the secondary classes. What would...
|
by: Phill |
last post by:
Anyone know the internal working of this thing. I expected it to be
kinda slow at enumerating large lists of objects but it was actually
pretty good. I was able to write a quick linked list class that beat
it at enumerating but was not as fast as the arrayList at actually
adding the items into the list.
This makes me think it is using something like linked arrays. Where
instead of allocating a new node each time an object is added it...
|
by: maya |
last post by:
Hi,
I'm writing an application that gets a string as an input from the
user, and creates an image with this string.
The library that creates the image doesn't recognize if the string is
a right-to-left string, so in such case, I need to create a mirror
string.
How can I know if the string that I got from the user is in a BiDi
language?
Thanks,
Maya
| |
by: sam.m.gardiner |
last post by:
I'm working with VB.NET events and I want a way to disconnect all the
handlers of an event. I want to do this in the object that is the
source of the event. This is slightly tricky in VB.Net as the eventing
code is slightly hidden.
when you use events in Vb.Net you type this:
<code>
Public event MyEvent()
</code>
|
by: jht5945 |
last post by:
For example I wrote a function:
function Func()
{
// do something
}
we can call it like:
var obj = new Func(); // call it as a constructor
or
var result = Func(); // call it as a function
|
by: kaczmar2 |
last post by:
I have an ASP.NET page where controls are created dynamically, and I
have an issue where one event handler creates another set of controls,
and then adds event handlers to those controls. The problem comes in
where I need to raise the event in the second control - the event does
not fire. I have distilled the example below down to it simplest:
on Page_Load one button is created, and a Click event hander is added
to the button. When...
|
by: active |
last post by:
I'm in the PictureBox click event and I need to know which button was
pressed.
I'm sure I once saw a property in Form or SystemInformation or someplace
that system wide that enabled one to determine which button is down.
But now that I need it I can't find it.
Maybe it was in Window API.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |