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

Checking Validity of uninitialized object

I have a struct that I am creating an object for but not initializing
it. Later on under certain conditions it gets
set to the values of another struct. However I have to check this
struct for an valid instance and sometimes it is
not a valid instance and gives an exception. Since I cannot use a null
for a value type how would I check for the
validity of the object.

For example:

one.cs contains
------------------------
in a loop :
{
myObject firstInstance;

if firstInstance is valid then
do...something.

setvals ();
}

second.cs contains:
------------------------------
setvals()
{
firstInstance = validInstance;
}

May 16 '06 #1
1 2108
You need an "isValid" boolean or something like it in your struct. The
CLR guarantees that when your struct is first created all booleans will
be "false".

If you are using .NET 2.0 then you can get this same effect by using
the "?" suffix to your type, e.g.:

myStruct? firstInstance;

will create a "nullable" struct.

May 16 '06 #2

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

Similar topics

9
by: Bart Nessux | last post by:
Are these equivelent? Is one approach prefered over the other #check to see if var contains something... if so proceed. if var is not None: continue #check to see if var is empty... if so...
15
by: Robert Mark Bram | last post by:
Hi All! I have the following code in an asp page whose language tag is: <%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%> // Find request variables. var edition = Request.Form ("edition"); var...
7
by: Michael Sgier | last post by:
Hi folks class X { private: CTexture *modelTex; // texture data } CTexture* X::Load()
99
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
3
by: Sam Martin | last post by:
hi all, I'm looking for your opinions on whether to validate and subsequenly throw exceptions based on the data set() to an object's property or whether you should do it on say a Save() method....
3
by: The Other Mike | last post by:
In my existing Powerbuilder application I have several statements that check to make sure an object is instatiated. ie. If isvalid(form1) then.... Is there a way to check for this in VB.NET?...
351
by: CBFalconer | last post by:
We often find hidden, and totally unnecessary, assumptions being made in code. The following leans heavily on one particular example, which happens to be in C. However similar things can (and...
0
by: rdemyan | last post by:
Is there a way to check the validity of front-end table links on a backend file where all permissions to data have been revoked. To get at the data, the front end uses RWOP queries. What I'm...
9
by: xhe | last post by:
Hi, I need to program to check the validity of IP address through PHP Initially I used this one: $url="http://www.ntc.gov.au/ViewPage.aspx? page=A02400304500100020"; $fp=fopen($url,"r");...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.