473,785 Members | 2,372 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

is it possible to use out and ref keyword together???

hi,
currently iam working on c#
i need to pass a parameter inside a function which is a OUT parameter
and i need to pass it as a reference how to do this?
please help me regarding this issue........

regards
bharathi

Nov 24 '06 #1
6 1501
Hi Selva,
OUT parameter works exactly as reference parameter. The only difference
is that you do not need to initialize the OUT variable before passing
the variable to the method.

if you want to force the method user to pass some data to the method,
you can use ref, if not use OUT. In both the cases data changes to the
param would reflect back to the calling method.

Thanks
-Cnu

selva wrote:
hi,
currently iam working on c#
i need to pass a parameter inside a function which is a OUT parameter
and i need to pass it as a reference how to do this?
please help me regarding this issue........

regards
bharathi
Nov 24 '06 #2
You might also wish to consider an alternative design to using OUT or
ref and
instead return single "values" or return an immutable structure if you
need to
return more than one "value".

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Nov 24 '06 #3

if you are use a ref type ,you didn't need to use the ref/out :)

On Nov 24, 2:23 pm, "selva" <kselvaaku...@y ahoo.co.inwrote :
hi,
currently iam working on c#
i need to pass a parameter inside a function which is a OUT parameter
and i need to pass it as a reference how to do this?
please help me regarding this issue........

regards
bharathi
Nov 24 '06 #4
In 99.9% of cases. There are (rare) occasions when you genuinely intend to
reassign a reference that was passed in, and you can't (for some reason)
return the new reference in the return value.

But yes; in many cases "ref" on a reference type parameter is due to
misconceptions. In contrast, "out" is IMO becoming more mainstream and more
useful that "ref", largely due to adopting the TryGetValue and TryParse
signatures from the 2.0 classes.

Marc
Nov 24 '06 #5

Does anyone know why C# does not support "const" keyword on parameter
to avoid reassign the reference? That keyword makes me feel much more
confident when passing reference-type argument.

It is so rare to see reference-type passed by ref (except for
developers who just switched from some other language). But "out", I
think, is OK. It indicates that the author just wants something out,
and don't need to instantiate the variable before passing (null is OK).
Without "out", it suggests that the author wants to gather some
additional info into and existing variable.

Thi
http://thith.blogspot.com

Marc Gravell wrote:
In 99.9% of cases. There are (rare) occasions when you genuinely intend to
reassign a reference that was passed in, and you can't (for some reason)
return the new reference in the return value.

But yes; in many cases "ref" on a reference type parameter is due to
misconceptions. In contrast, "out" is IMO becoming more mainstream and more
useful that "ref", largely due to adopting the TryGetValue and TryParse
signatures from the 2.0 classes.

Marc
Nov 24 '06 #6
Marc... I agree that using a single out parameter is useful as in
TryParse, but a more object oriented approach is simpler and less error
prone for multiple parameters. For instance:

public Mortgage.Calcul ation Calculate(Mortg age.Parameters m)
{
return Calculate(m.Pri ncipal, m.Interest, m.Months, m.Payment,
m.Target);
}

Is easier to use and less error prone than:

private bool TryCalculate(Mo rtgage.Paramete rs p,out double
principal,out double interest,out int months,out double payment,out int
target)
{
Mortgage.Calcul ation result= this.Calculate( p.Principal,
p.Interest, p.Months, p.Payment, p.Target);
principal = result.Principa l;
interest = result.Interest ;
months = result.Months;
payment = result.Payment;
target = result.Target;

return result.IsValid( );
}

Regards,
Jeff
>But yes; in many cases "ref" on a reference type parameter is due to
misconceptions. In contrast, "out" is IMO becoming more mainstream and
more useful that "ref", largely due to adopting the TryGetValue and
TryParse signatures from the 2.0 classes.<
*** Sent via Developersdex http://www.developersdex.com ***
Nov 26 '06 #7

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

Similar topics

6
4620
by: Roy Smith | last post by:
I've got a function that takes a couple of optional keyword arguments. I want to check to make sure I didn't get passed an argument I didn't expect. Right now I'm doing: conversion = None drop = False for key, value in kwArgs.items(): if key == 'conversion': conversion = value elif key == 'drop':
3
7879
by: Jonathan | last post by:
Hi all! For a match schedule I would like to find all possible combinations of teams playing home and away (without teams playing to themselves of course). I now the simple version works something like this: For a (very) simple table containing three rows like this: row 1: A
59
3947
by: seberino | last post by:
I've heard 2 people complain that word 'global' is confusing. Perhaps 'modulescope' or 'module' would be better? Am I the first peope to have thought of this and suggested it? Is this a candidate for Python 3000 yet? Chris
7
1981
by: Rakesh Rajan | last post by:
Hi, I find that when i define a delegate, it gets derived from MulticastDelegate, which provides all funtionality that events would provide (like registering new handlers etc.). Then, apart from being a bit more neater, could there have been any other reason that an 'event' keyword became necessary in C#? Thanks in advance, --
15
21134
by: Ben | last post by:
Hey, Not sure if this is the right group to post this on, so sorry in advance if it isn't. I'm using the VS.NET 2005 beta, and am trying to fill one grid, based on what is selected in the other grid. So, in the SelectionChanged event, I get the IDs of the selected rows in the first grid, and.. this is where i get stuck :)
8
3517
by: Bryan Parkoff | last post by:
int has two bytes or four bytes. long has four bytes or eight bytes. I can't be sure to choose int or long keyword because I don't trust to get the wrong size. I always check by using sizeof(...). I always use "short int" to show two bytes and "long int" to show four bytes. It may not be accurate when I port my code from Microsoft C/C++ Compiler to other C/C++ Compiler such as Linux, Unix, Mac, etc. I always trust Microsoft's keyword...
11
2027
by: vbgunz | last post by:
Hello all, I am just learning Python and have come across something I feel might be a bug. Please enlightenment me... The following code presents a challenge. How in the world do you provide an argument for *arg4? ## ============================================================ def argPrecedence(par1, par2=0, par3=0, *par4, **par5): print 'par1 =', par1, ' # positional argument' print 'par2 =', par2, ' # keyword argument'
1
1576
by: Sandra-24 | last post by:
I've always wondered why I can't do: def foo(a,b,c): return a,b,c args = range(2) foo(*args, c = 2) When you can do:
3
5402
by: Redbeard | last post by:
Hi All this is my first time post, be gentle. I am looking at creating a keyword search that searches multiple fields in a Form and then filters records that match the keyword. The Form currently has a button that connects to a Query that run the keyword search in several field and then filters the results. The problem is that I can not do a search within a search, or have multiple words searched in any order. For example there are 20,000...
0
9643
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, 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...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8968
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
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...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4045
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
3
2877
bsmnconsultancy
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...

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.