473,408 Members | 2,832 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,408 software developers and data experts.

C# CSharp Reset Struct Class Memory



Hi,
I have a class, cerated like a struc for some reasons, and I want to
reset all values in it.

public class MyClass
{
public byte Channel;
public byte SatelliteID;
public byte SyncFlags;
public byte PhaseErrorCount;
}

After filling the class with some values, I want to reset all values
to the default, like the first time it was created.
I can do this filling every parameter, but I have some classes with a
lot of parameteres.
there is a way to reset this class? For example clear the memory
occupied by the class.
I know that I can make assigning a NULL to the class and recreate it,
but I search another way.

THank you very much

Mar 21 '07 #1
2 3111
Sheikko,

Well, to be quite honest, I think letting the old class go and creating
a new instance is the best option. You stated that you wanted to reset all
the values to the default like when they are constructed, so why not use
what the language offers you? What are you hoping to gain by resetting the
fields to all the values as opposed to just creating a new instance of the
class?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sheikko" <sh*****@gmail.comwrote in message
news:11**********************@b75g2000hsg.googlegr oups.com...
>

Hi,
I have a class, cerated like a struc for some reasons, and I want to
reset all values in it.

public class MyClass
{
public byte Channel;
public byte SatelliteID;
public byte SyncFlags;
public byte PhaseErrorCount;
}

After filling the class with some values, I want to reset all values
to the default, like the first time it was created.
I can do this filling every parameter, but I have some classes with a
lot of parameteres.
there is a way to reset this class? For example clear the memory
occupied by the class.
I know that I can make assigning a NULL to the class and recreate it,
but I search another way.

THank you very much

Mar 21 '07 #2
Sheikko <sh*****@gmail.comwrote:
I have a class, cerated like a struc for some reasons, and I want to
reset all values in it.

public class MyClass
{
public byte Channel;
public byte SatelliteID;
public byte SyncFlags;
public byte PhaseErrorCount;
}

After filling the class with some values, I want to reset all values
to the default, like the first time it was created.
I can do this filling every parameter, but I have some classes with a
lot of parameteres.
there is a way to reset this class? For example clear the memory
occupied by the class.
I know that I can make assigning a NULL to the class and recreate it,
but I search another way.
As Nicholas said, that's a fairly odd thing to do. You could use
reflection, although it wouldn't be terribly fast. You also need to
consider what you want to happen if there's inheritance involved.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 21 '07 #3

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

Similar topics

20
by: fix | last post by:
Hi all, I feel unclear about what my code is doing, although it works but I am not sure if there is any possible bug, please help me to verify it. This is a trie node (just similar to tree nodes)...
26
by: phoenix | last post by:
Hello, I've got a design question. I need to keep track of some variables and I am planning to put them inside a class or struct. Basically I'm talking about 10 bools, 20 ints and 2 arrays of...
3
by: Karl M | last post by:
Hi everyone, I just notice some strange behaviors on the MS C++ compiler regarding struct default constructor, see the example bellow: struct MyStruct { int a; }; class MyClass { public:
3
by: GrkEngineer | last post by:
I recently had to use someone's struct from a native app to receive data over Udp. The struct has a array member which looked like this: struct sensorHdr{ char sName; }; When I tried to make...
4
by: DaHool | last post by:
Hi there !!! I browsed around the Internet in search for a solution of a little difficult problem i have in VB.NET.... However, i cannot find a suitable anwser anywhere, so i thought i'll give...
15
by: cody | last post by:
currently when trying to change a struct returned by a property, the compiler generates an error. so if you try someControl.Location.Y = 10; you get an error which is logical if one...
11
by: garyusenet | last post by:
I have 'cli via c# on order', and in the mean time am reading 'Pro C# 2005 and the .NET platform' (Andrew Troelson). I'm just reading about the 'five types defined in the CTS'. Specifically Struct....
74
by: Zytan | last post by:
I have a struct constructor to initialize all of my private (or public readonly) fields. There still exists the default constructor that sets them all to zero. Is there a way to remove the...
0
by: jimmy.dansbo | last post by:
Hi, I am trying to use iscsidsc.dll in a csharp program, but have a lot of trouble with it. One thing I have working is GetIScsiInitiatorNodeName in the following way: public static extern...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
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,...
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.