.net - Differentiate Between Value Type And Reference Type?
Mar 7, 2011
I also.But problem is I generally mug up things for identifying that it is value type or reference type Like class is reference type and structure is value type .. I made a list and paste in my mind .. But of course it is wrong. how to differenciate between value type and reference type by its behaviour or looking at its properties or run time behaviour etc .So that I need not to remember the list..
View 4 Replies
ADVERTISEMENT
Mar 27, 2012
I know a little about using a user specified type IE IIf(Of ReturnType)(ByVal expression as Boolean, ByVal TruePart As ReturnType, ByVal FalsePart As ReturnType) As ReturnType...Which works, however I've been trying to get this to work, but can't..
Protected Function InverseSign(Of ReturnType)(ByVal value As Double) As ReturnType
Dim result As String
Select Case Math.Sign(value)
Case -1: result = "+" & Math.Abs(value).ToString()
[code]....
Using try cast just gives me the error saying ReturnType has no class-constraints? whatever that means..But my goal here is to be able to return either a string or double.. However every method I've tried to convert my result string to the ReturnType doesn't work.I've also tried simply overloading the function, but I can't because they only differ by return type. So that didn't work either.
View 1 Replies
Oct 13, 2010
I've come from a Assembler and C/C++ background, so I understand the concept behind reference types versus value types in vb.net. Also, I've read Jon Skeet's article regarding references and value types and I understand all of that. My question is: How can you tell if a given type is a reference type or a value type? Is it simply that all integral types (ints, floats, etc.) are value types and all classes are reference types? (If so, where do strings fall?)
[Code]...
View 1 Replies
Sep 11, 2009
In VB.NET, if I create a class it is a reference-type. But, if that class it chock full of value type properties, how is this handled? If the class is instantied but never filled, I suspect a pointed for to the heap is allocated. But is more space allocated on the stack for all of it's value type properties?
View 4 Replies
Oct 5, 2010
In .NET, integer data type is a value type(stack) and String is a reference type(heap). So If a class A has an integer, and a string type object in it, and a class B creates an object of class A, then how will this object of class A be stored in memory? In stack, or in a heap? This was asked in my Microsoft interview. Need to understand how I fared.
View 3 Replies
Apr 5, 2011
When I try this, I get the compiler error below:Return TryCast(obj, Double?)'TryCast' operand must be reference type, but 'Double?' is a value type.
This confuses me, I thought that when you make a value type nullable, boxing will be applied - which results in a reference type?
View 3 Replies
Aug 5, 2009
I'm doing some reading up on the differences between Value types and Reference types - is there any quick/easy way of telling whether a type is Value or Reference? I couldnt see anything in Intellisense so had a look at MSDN pages for a few classes [URL]but it doesnt seem to mention it there either.
View 11 Replies
Jan 12, 2010
I've got a class, lets call it Person, which needs to keep some data (in the form of another class which we will call PersonData) in one of its properties - the problem is that I will have several instances of this person class and they all need their own 'copy' of the data (just in memory, its not a file or anything).Hhow would I do this? At the moment because everything involved is a Reference type, I'm assuming that if I were to create 2 instances of my Person classes and assign the same instance of the PersonData class to their properties then when one Person class made a change to the PersonData it would be reflected in the other Person class right? How can I avoid that and make it so that they both have their own version of the data, without having to repeat the procedure that fetches the data in the first place?
I'll explain my exact situation just in case it helps, but this is more of a general question as I could probably get around it in this case by copying the byte array I receive from the server (hopefully that will make sense once you read the explanation below) :
In this case the data I am talking about copying is actually received from a server via TcpClient. The thing is, when the client requests the data from the server over the network, the server has to go off and query several other servers etc so I do not want to be requesting data from the server every single time as that would be a big waste of resources and time. So when a request is made and data is received back from the server, several of these Person class instances will be created (in reality, its a few different classes but that doesnt make a difference for this example) and each need to have access to the full data that the server has sent back but in some cases the Person instances might need to modify the data and this is where the problem appears as they will all be working on the same data.
View 6 Replies
Mar 16, 2010
I have a mutable class that I'm using as a key to a generic dictionary. Two keys should be equal only if their references are equal. From what I've read, in this case, I don't need to override Equals, GetHashCode , or implement IEqualityComparer.
View 5 Replies
May 10, 2011
As the reference values are stored in the heap as a data; where do the type information of any reference value is stored?If there are a couple of instances of class Artist; when they are stored in the heap how the .Net tags those memory blocks as type of Artist?
View 3 Replies
Jul 22, 2009
I m working on one of vb6 projects. There are total 3 projects. One of them is ActiveX Exe is and has main method, second one is also AxtiveX Exe but doesnt have main method (only Classes) and third project is of ActiveX Dll.Well I m trying debug and issue and trying to put all 3 prjts in 1 Group prject but some how I cant add reference of 2nd prject into the first one. I get an error of " cannot be referenced because its project type is exe" but I can add a ref of its compiled exe but this doesnt help in debugging of whole prjt.
View 7 Replies
May 18, 2011
I'm trying to create a generic function to build a Linq expression from a list of Telerik grid filters. I'm trying to stay clear of dynamic Linq. Because I don't know the type that I'm building the expression for, I'm attempting to use reflection in the lambda functions to refer to a property, but after applying the fix suggested by @JaredPar I get the error, "The LINQ expression node type 'Invoke' is not supported in LINQ to Entities." Is there any way around this? here is my code:
Public Shared Function buildRadFilter(Of T)(ByVal filterExpression As List(Of GridFilterExpression)) As Expressions.Expression(Of Func(Of T, Boolean))
Dim returnPred = PredicateBuilder.True(Of T)()
[Code]....
View 1 Replies
Aug 11, 2010
I have searched for two weeks, every night, exhaustively reading forum threads and trying all suggested solutions no matter how outlandish. Just as is the case with the many many forum threads about this same issue, the site works fine on my development machine. It deploys with no errors. It works from the production server and reads data from the database, but when it attempts to access a profile it crashes with this error.
A number of posts say to check or uncheck an option called "remove app_code.compiled file" but apparently this was a Visual Studio 2005 option. It is nowhere to be found in Visual Studio 2010. A number of posts say to make sure the App_Code.dll is present in my bin directory. It is present. I've deleted the app_code.compile file manually to see if that made any difference. I've changed the target framework from 4.0 to 2.0 and 3.5. I've completely deleted the site in IIS, created a different folder with a different name and redeployed the site with every combination of "allow this precompiled site to be updatable" and "Use fixed naming and single page assemblies".
i've included references to System.Web.Profile and System.Web and System.Web.Profile.ProfileCommon. I've created a new, fresh website targeting .net framework v4.0 and copied that web.config file to my application and recreated my profile entries to ensure that I didn't jack anything up in the config file along the way.
View 3 Replies
Jun 24, 2010
I have a big problem.I'm starting with Visual Basic (2008) and I get this error when you want to run the program,
Warning 2.Unable to load the type library for reference "MSCommLib.Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)) prjRxData
View 5 Replies
Dec 21, 2009
I have an issue with a third-party COM+ DLL meant to be used from VB6, where it has a function to set a Callback for a hardware event. However, I'm using VB.NET, and AddressOf now returns a reference type instead of an integral type, which means that the setCallback function on the COM+ DLL apparently can't be used.
View 1 Replies
Jan 28, 2012
when view in browser, i got this error: Unable to cast object of type 'ASP.webform1_aspx' to type 'System.Web.UI.WebControls.Button'.
how should i solve this problem?
Line 7: If Not Page.IsPostBack Then
Line 8: Dim rowIndex As Integer = 0
<b>Line 9: Dim btn As Button = DirectCast(sender, Button)</b>
[Code].....
View 2 Replies
Mar 22, 2010
I'm trying to add a new record to my database but i keep getting the message - "conversion from type DBnull to type string is not valid". I think its something to do with the Employee ID when VB attempts to save it to the database my code is below
Imports System.Data.OleDb
Public Class Add
Private Sub DisplayRow()
[Code]....
View 5 Replies
May 25, 2011
I now have SQL Parameters set up and I'm using them to save/delete/add my data. This all works well, except when it's trying to save a combobox to the datatable it appears with the error above.Majority of my comboboxes have datasources, and the valuemembers of these are the actual list items, not the ID's of the list items.I'm not sure why this error could be happening, I'm fairly sure I've connected everything to the binding source correctly; I've checked it a few times.Does anybody know what the cause of this could be? I've looked around a bit and I haven't found much
View 7 Replies
Mar 1, 2012
I've spent quite a bit of time reading up on generics, covariance, etc., and I am failing to understand why I get the aforementioned compiler error in this type of codeLet's say I have a base "Bill" class made up of a collection of Lines..
Public Class Bill(Of L As Line)
Private _lines As List(Of L)
Public Property Lines() As List(Of L)
[code].....
View 11 Replies
Dec 22, 2009
E.g. how do I get VB.Net to statically type a local variable to be the static type of the expression on the right had side of the assignment?
View 1 Replies
Apr 19, 2010
I had write code (just for learning), the codes :
dim Temp as string
Temp = Recordset("
Table_Field")
but, when I start Debugging the error messages "Unable to cast object of type 'ADODB.InternalField' to type 'System.String"
View 2 Replies
Apr 13, 2011
I am implementing IMAPI2 into my vb.net project but ran into a wall. I am getting the message Unable to cast object of type 'IMAPI2FS.FsiStreamClass' to type 'IMAPI2.IStream' when trying to start the burn. I googled around and found this is something that microsoft hasn't fixed.. which basically renders IMAPI2 useless in vb.net.
I found a post on codeproject.com by eric hadden who combined the IMAPI2.dll and IMAPI2fs.dll into an c# interop file. I also see the IBURN interop in microsoft SDK samples. I'd like to use either, but it's in c# and I'm using vb express. Does anyone know a way to get the interop into visual basic or a way around "Unable to cast object of type 'IMAPI2FS.FsiStreamClass' to type 'IMAPI2.IStream'"?
View 1 Replies
Jun 1, 2009
I'm having a problem with converting from one source type to a destination type. I have a form with 2 buttons (button 2 uses the OpenFileDialog to have the user open an excel file set to NewFile),(button 1 takes the contents from specific cells in NewFile and arranges them how I need into oXLApp1).
The error I get is "Unable to cast object of type 'System.IO.FileStream' to type 'Excel.Application'." in line 14 of the code below.
Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
[Code]....
View 4 Replies
Mar 19, 2009
I'm new to VB 2005, the code below is actualy coded from VB 6 and just converted it to VB 2005. I'm having trouble with line that's on bold letters.In VB 6 this works just ok. By the way the error message is "Unable to cast object of type 'System.String' to type 'ADODB.Connection'." [code]
View 5 Replies
Aug 20, 2009
I have a number of controls (Device1, Device2, etc.) that all inherit from BaseDeviceControl. In the DragEnter event handler I am trying to test for the correct type by using the BaseDevvceControl like this....
[Code]....
View 8 Replies
May 5, 2009
I'm compiling a VB.Net 2.0 app (created in VS2008) using msbuild, and now I've added a generic return type, it's giving me the following:
Warning: Type library exporter encountered a generic type instance in a signature. Generic code may not be exported to COM.
Having just spent ages removing all of the previous warnings, I don't really want to add a new one. Any idea how to get rid of it (aside from not using generics)?I don't know what details I'd put in the attribute, or what number to put in the project-level ignore list.
View 1 Replies
Feb 7, 2012
I am pulling data from a local MSSQL database using a stored procedure, then send the data to a web service. Every part of the component works well except for a pesky problem will a DBNull being returned from the DataRow field, when I know that the field is not null and has valid data. The database and associated INSERT statements that add to this field are designed to not allow NULL entries. When I debug break the program on or right before the line that throws the error I see that the field has valid data for the current row.If I add a null check to the code (as below) the operation continues as normal:
Dim dataResultsTable = Me.myViewTableAdapter.GetData(int)
For Each myDataRow In dataResultsTable.Rows
If worker.CancellationPending Then
[code]....
Why is the read operation returning DBNull instead of the data in the database?
EDIT: Just to be clear, the operation does return the proper data, but the data is not being saved into the variable.
View 2 Replies
Feb 21, 2012
I declare my dates as the following in my code:
Dim DeliveryDate as Date
But i am now trying to declare time however i keep getting an error because i cannot get the type correct. I tried the following but get the following error: "Conversion from type 'Timespan' to type 'integer' is not valid".
Dim DeliveryTime as DateTime
Dim DeliveryTime as Integer
In my database the DeliveryTime type is set to Time(7) so i would assume there should be 'Time' which i could use to declare it, but there isnt. What is the correct type i should be using?
Here is my exact code. There error is Input string was not in correct format:
GraphDate4 = String.Empty
DeliveryProducts = "{ name: 'DeliveryProducts', data: ["
If DataReader4.HasRows Then
[Code].....
View 1 Replies
May 24, 2011
I can't cast my objects. I get: "Unable to cast object of type 'ClassA' to type 'ClassB'".
The service Class:
Public Class svc_Insp
Implements Isvc_Insp
Public Function Test(ByVal pm_income As ClassC) As String Implements Isvc_Insp.Test
[code]....
View 1 Replies
Oct 10, 2010
I'm getting the error "Conversion from type 'DBNull' to type 'Date' is not valid."here's the line generating the error.
dtReady.Value = dSet.Tables("Db").Rows(Inc).Item("Fixed_Date")
I'm using a date/time picker control and sending the db value to it. I know that the value is null, but I don't understand why the Picker can't be blank. Is there a way to let it be blank? Or should I set up a way to check for nulls and assign today's date or something just in case?
View 5 Replies