473,396 Members | 2,017 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.

out parameter declaration

Coy
Hi,

I'm trying to smuggle a bool result back to my ASP.NET layer
from my data layer, via my business layer. I thought I'd just
declare a bool in the web ui code and pass it in a call declared
for an 'out bool' in the business layer. The business layer would
then just pass in on to in a call declared for an 'out bool' in the
data layer. I thought wrong. What are the rules for this?

I keep getting "cannot convert from 'bool' to 'out bool'." I'm not
clear on how to declare the parameter, because it seems I'm just
migrating the compiler error from one layer to another as I try
different combinations. The only thing I'm clear on so far is that
I can't use 'out' or 'ref' outside of a method signature to try and
'cast' my way out of the compiler error. I'm not convinced that
'out' can span more than a single call. I'm also not happy
having to make more than a single assignment to the argument
which I'd like to exclusively do at the data layer. In other words
why can't an 'out' just work like a reference does in C++?

Thanks


Nov 15 '05 #1
1 2860
Here an example I just posted earlier. Notice the out uint. In your case
you would use a bool.
Call the first like so:

uint num;
if ( IsUInt("mystring", out num) )
{
//do something with num.
}

===
public static bool IsUInt(string str, out uint val)
{
val = 0;
if ( str == null )
return false;
char [] cArray = str.ToCharArray();
return Bits.IsUInt(cArray, out val);
}

public static bool IsUInt(char[] cArray, out uint val)
{
val = 0;
if ( cArray == null || cArray.Length == 0 )
return false;

if ( cArray.Length > 10 )
return false;

long numPlace = 1;
long num = 0;
byte b = 0;
for (int i = cArray.Length - 1; i >= 0; i--)
{
if (cArray[i] > 57 || cArray[i] < 48)
return false;
b = (byte)(cArray[i] - 48);
num = num + ( b * numPlace );
numPlace = numPlace * 10;
}

if ( num > uint.MaxValue )
return false;

val = (uint)num;
return true;
}

public static bool IsInt(string str, out int val)
{
val = 0;
if ( str == null )
return false;
char [] cArray = str.ToCharArray();
return Bits.IsInt(cArray, out val);
}

public static bool IsInt(char[] cArray, out int val)
{
val = 0;
if ( cArray == null || cArray.Length == 0 )
return false;

if ( cArray.Length > 11 ) //10 max numerics plus one minus sign.
return false;

long numPlace = 1;
long num = 0;
byte b = 0;
int signed = 1;

if ( cArray[0] == '-' )
{
signed = -1;
cArray[0] = '0';
if ( cArray.Length == 1 )
return false;
}

for (int i = cArray.Length - 1; i >= 0; i--)
{
if (cArray[i] > 57 || cArray[i] < 48)
return false;
b = (byte)(cArray[i] - 48);
num = num + ( b * numPlace );
numPlace = numPlace * 10;
}

num = num * signed;

if ( num > int.MaxValue || num < int.MinValue )
return false;

val = (int)num;
return true;
}
--
William Stacey, MVP

"Coy" <w.*******@comcast.net> wrote in message
news:uA**************@TK2MSFTNGP09.phx.gbl...
Hi,

I'm trying to smuggle a bool result back to my ASP.NET layer
from my data layer, via my business layer. I thought I'd just
declare a bool in the web ui code and pass it in a call declared
for an 'out bool' in the business layer. The business layer would
then just pass in on to in a call declared for an 'out bool' in the
data layer. I thought wrong. What are the rules for this?

I keep getting "cannot convert from 'bool' to 'out bool'." I'm not
clear on how to declare the parameter, because it seems I'm just
migrating the compiler error from one layer to another as I try
different combinations. The only thing I'm clear on so far is that
I can't use 'out' or 'ref' outside of a method signature to try and
'cast' my way out of the compiler error. I'm not convinced that
'out' can span more than a single call. I'm also not happy
having to make more than a single assignment to the argument
which I'd like to exclusively do at the data layer. In other words
why can't an 'out' just work like a reference does in C++?

Thanks

Nov 15 '05 #2

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

Similar topics

3
by: Aguilar, James | last post by:
Hey all. I was making a newbie mistake that I eventually figured out. That is not my question. My question is about the error message. So let me set the stage for you: class Superclass {...
7
by: Michael Birkmose | last post by:
Hi, Using gcc the following is possible: int some_function(struct local_struct { int member;} a); This function takes one parameter "a" of the type struct local_struct. This type is...
15
by: Daniel Rudy | last post by:
Hello, Consider the following code: /* resolve_hostname this resolves the hostname into an ip address. */ static void resolve_hostname(char result, const char hostname, const char server) {
6
by: August Karlstrom | last post by:
Hi What's the cause of the inconsistency between variable and parameter declarations in C? What's wrong with e.g. void f(int a, b; char c); August
15
by: main() | last post by:
Hi all, When i compile following piece of code, # include <stdio.h> void fun(int val) { int val; /*problem is here*/ printf("%d\n",val);
11
by: wuzertheloser | last post by:
Write a program which calculates the integral of the function f(x)=(A*x^m)/n! on the interval from a to b (0<a<b). In the main program, scanf a double value for m and a...
4
by: harifajri | last post by:
Hi All, We know that if we want to list down all methods/functions on an unmanaged DLL, we can use command-line tools 'dumpbin' or 'link ' For example, if we want to know method from...
7
by: W Marsh | last post by:
Hi, Could anybody tell me wh the parameter "T val" is not marked const in this Stroustrup code, considering that val is not modified and not non- const methods called? template<class C,...
8
by: flopbucket | last post by:
Hi, I want to provide a specialization of a class for any type T that is a std::map. template<typename T> class Foo { // ... };
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.