.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Interview Question >> ASP.Net >> Post New Question Subscribe to Interview Questions

How do I call a member method and pass a primitive type (Value Type) by reference?

Posted By :Shashi Ray     Posted Date :March 30, 2009    Points :10   Category :ASP.Net 
Use the ref keyword when declaring the parameter of the method, for example:

public bool GetValue( ref int returnValue );

This will pass the numeric by reference.You can modify the value of returnValue within the body of GetValue and it will persist when the method call returns.

You can also find related Interview Question to How do I call a member method and pass a primitive type (Value Type) by reference?  below: 

How do you call a Member method and pass a value Type by reference?

use the "ref" keyword when declaring a Parameter of the Method
public bool GetValue(ref int returnvalue);

How do you call a Member method and pass a value Type by reference?

use the "ref" keyword when declaring a Parameter of the Method (More...)

Value type & reference types difference? Example from .NET. Integer & struct are value types or reference types in .NET?

Most programming languages provide builtin data types, such as integers and floatingpointnumbers, that are copied when they are passed as arguments (that is, they are passed by value). In the .NET Framework, these are called value types. The runtime

supports two kinds of value types:
· Builtin
value types
The .NET Framework defines builtin
value types, such as System.Int32 and
System.Boolean, which correspond and are identical to primitive data types
used by programming languages.
· Userdefined
value types
Your language will provide ways to define your own value types, which derive from System.ValueType. If you want to define a type representing a value that is small, such as a complex number (using two floatingpoint numbers),
you might choose to define it as a value type because you can pass the value type efficiently by value. If the type you are defining would be more efficiently passed by reference, you should define it as a class instead.

Variables of reference types, referred to as objects, store references to the actual data. This following are the reference types:
· class
· interface
· delegate
This following are the builtin
reference types:
· object (More...)

convert a value-type to a reference type is known as?


Boxing is the terminology used in .NET Framework to convert Value type to reference type (More...)

convert a Reference Type to a Value type is known as?


UnBoxing is the terminology used in .NET Framework to convert Reference Type to a Value type (More...)

Why do I get an error (CS1006) when trying to declare a method without specifying a return type?

If you leave off the return type on a method declaration, the compiler thinks you are trying to declare a constructor. So if you are trying to declare a method that returns nothing, use void. The following is an example: // This results in a CS1006 error public static staticMethod (mainStatic obj) // This will work as wanted public static void staticMethod (mainStatic obj) (More...)

what is the difference between value type and reference type?

Value type is stored in stack.
Reference type stored in heap. (More...)

Is array reference type / value type?

Array is a reference type and it is stored in Heap memory!

Reference types are:


Is string reference type / value type?

string is reference type
because String is immutable objects..........
means does not change the values(string)....... (More...)

What is Reference type and value type ?

Reference Type:
Reference types are allocated on the managed CLR heap, just like object types.
A data type that is stored as a reference to the value's location. The value of a reference type is the location of the sequence of bits
that represent the type's data. Reference types can be self-describing types, pointer types, or interface types

Value Type:
Value types are allocated on the stack just like primitive types in VBScript, VB6 and C/C++. Value types are not instantiated using new go out of scope when the function they are defined within returns.
Value types in the CLR are defined as types that derive from system.valueType.

A data type that fully describes a value by specifying the sequence of bits that constitutes the value's representation. Type information for a value type instance is not stored with the instance at run time, but it is available in metadata. Value type instances can be treated as objects using boxing.

Is String a primitive type?

No, the string is not a primitive type.
However, it has some characteristics common with the primitive types.
The language supports string literals in the code, so that you don't have to explicitly create Stringinstances using the new keyword to get a string object.
There is also support for concatenating strings using the + operator, which the compiler turns into a call to the String.Concat method.
Strings are immutable, which means that it in most situations has value type semantics, just like the primitive types.

Explain Value type and reference type?

Value Type
Variables of value types directly contain their data.
Value types store in stack.
Reference Type
Variables of reference types store references to their data
Reference types store in Heap Memory.


Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend