C# :: Determining Object Equivalence For Value Types, Reference Types And ILists?

Nov 1, 2009

I have a class with a Property called 'Value' which is of type Object.Value can be of any type, a structure, a class, an array, IList etc.My problem is with the setter and determining whether the value has changed or not.This is simple enough for value types, but reference types and lists present a problem.For a class, would you assume that the Equals method has been implemented correctly, or just assume that the value has changed every time the setter is called?If I did assume it's changed, then perhaps I should assume it for value types as well, so that the behaviour is consistent.

View 2 Replies


ADVERTISEMENT

Determining Variable Types?

Aug 18, 2009

I'm converted a VB6 project to vb.net using the convert tool.Now i have a few declares that included passing variables as "as any" which vb.net doesn't like and it seems you have to declare them as there correct type so i have the following,So i suppose , Long and Long

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"(ByRef Destination As Any, ByRef Source As Any, ByVal Length As Integer)
and

Long again?

Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Integer, ByVal nCode As Integer, ByVal wParam As Integer, ByRef lParam As Any) As Integer

View 8 Replies

Copying Reference Types?

Nov 6, 2011

I understand that an array variable contains a reference to an array object - it is a reference type. A string variable is also a reference type.So, if I make a copy of either one, a change to the copy should also change the result I get when I look at the original because both refer to the same object.

View 5 Replies

Copying Reference Types And String

Mar 2, 2010

I understand that an array variable contains a reference to an array object - it is a reference type. string variable is also a reference type. So, if I make a copy of either one, a change to the copy should also change the result I get when I look at the original because both refer to the same object. In the following code, I expected to see "Whoooy" as the result for original and copy for both the array and the string. It works with the array but not the string.

[Code]...

View 5 Replies

Passing Reference Types By Value (ByVal)

Aug 17, 2009

I'm still working on the code in this thread [URL] and as I mentioned in that thread, I thought that passing objects around between methods would probably be bad for performance (perhaps not really noticeably at first but maybe if I did it enough then it could have an impact).

1. When you pass a reference type to a method using ByVal then what is actually 'copied' ? I understand that ByVal copies the object into the local method that you are calling where as ByRef passes a reference to the actual object so you can work with the original object. So when you have a Reference type and you pass this ByVal then does copy the entire object or does it just copy a 'reference' to the object?

2. When working with an object that relates to a 'physical' item, such as a file on disk or a network stream between two connected machines, then what happens when you pass it around between methods (this might be irrelevant depending on the answer to the first question) ? I mean if I have a NetworkStream object that represents the data stream coming from a remote computer, if I then pass that ByVal into another method then does that mean I am still working with the same data stream or a copy of it or what?

View 9 Replies

Types Not Showing Up For Service Reference

May 30, 2012

I'm integrating one of our apps with a third-party provider's web service. I've added the service reference, but when I go to dimension a var as one of their types, the types aren't showing up for me in Intellisense. I'm using VB.NET/VS 2008 on Windows 7 and a 2.0 Framework web site running on local IIS. I have imported System.Web and System.Web.Service in my codebehind. I also made sure to check the "Always generate message contracts" checkbox.Types not showing up for service reference

View 2 Replies

VS 2008 - Values And Reference Types

Oct 29, 2011

Reading a book, the following examples are given regarding value and reference types. This example is noted as a value example. ptY display {x = 10, y = 20}

Dim ptX As New System.Drawing.Point(10, 20)
Dim ptY As New System.Drawing.Point
ptY = ptX
ptX.X = 200
Console.WriteLine(ptY.ToString())

This example is noted as a reference example. objY displays "Hello Test".
Dim objX As New System.Text.StringBuilder("Hello World")
Dim objY As System.Text.StringBuilder
objY = objX
objX.Replace("World", "Test")
Console.WriteLine(objY.ToString())

The idea is simple enough, but I just can not tell the difference between the two. Could someone explain how the heap, the stack and the New keyword play a role in accessing directly and indirectly objects and variables?

View 3 Replies

C# - Reference Types - See The Actual Reference?

Jan 11, 2012

The difference between reference types and value types is often confusing for beginners due to not understanding what a variable of value type actually holds. We know that:Value types store the actual valueReference types only store the reference to the object

View 4 Replies

Compare Two Types In Dictionary Of Types .net?

Jun 23, 2012

I need to compare two dictionary values if the types stored are equal, this is what i have

if gettype(Args(key)) = gettype(argtypes(key)) then
'' do something
end if

[Code]....

View 1 Replies

Structure Hold Small Number Of Reference Types?

Jun 10, 2009

Is it okay for a structure variable to hold a small number of reference types? I thinks it's fine because the pointers themselves are not that big, regardless of what they're pointing to. But I never did fully figure out the whole heap/stack thing, so I'd like to make sure.

View 6 Replies

VS 2010 Isnot Requires Operands That Have Reference Types?

Mar 4, 2012

First post here so Im sorry if im posting in the wrong place. Im trying to build a simple poker game which requires the program to recognise hands of each players. Luckily there are 3rd party solutions such as pokereval. However my problem comes when i try to convert a C# ported version of pokereval by Keith Rule, into vb.net. The following error shows up referring to the line with the *.

[Code]...

View 4 Replies

Using Object Types?

Sep 27, 2010

I understand that different data types have different uses, String for text, Integer for numerical ect. However, if the Object type can be used for ALL types and supportive of everthign then why should i worry about using correct data types such as string and integer if i can just use "Object" for them all and it will work.I could do

Dim Test as Object = "John"

or i could do

Dim Test as String = "John"

They both do the same thing; there must be something very important im missing here but can only think of one thing that it could be; Memory Management.I think that by using a type such as object may take up more memory than using string?

View 4 Replies

Asp.net - Copy Object Types ?

Jul 29, 2010

I am building an ASP.NET application that needs dynamic tables. That's another issue that I've already posted about (and gotten a pretty good response!). Now, I'm running into another issue - I want to add new rows to my table, but given that I will have 10-12 tables on one page, each containing different objects in their rows (text boxes, check boxes, etc.) I need a way of simply generically adding a new row that has the same objects as the first row in the table. Here's my code:

Private Sub AddTableRow(ByRef originalTable As System.Web.UI.WebControls.Table)

Dim originalRow As System.Web.UI.WebControls.TableRow = originalTable.Rows(1)
Dim insertingRow As New System.Web.UI.WebControls.TableRow[code]......

Stepping through with a debugger, I see that this strategy is working - but the additional table row still doesn't appear...and still does when I do this statically.

View 1 Replies

Creating An Object Array Of Different Object Types?

Mar 29, 2010

I am having some trouble creating an object array of different object types. Here is what I have so far:

Public Sub New()
Dim b1 As New Book("Book Title 1", "Gold Book Publisher", 1.0, "Bob Jones", "192DJDJD212", "01/02/10")
Dim b2 As New Book("Book Title 2", "Gold Book Publisher", 1.0, "Bob Jones", "192DJDJD212", "01/02/10")
Dim b3 As New Book("Book Title 3", "Gold Book Publisher", 1.0, "Bob Jones", "192DJDJD212", "01/02/10")

[code]....

If I define the array As Book (Public publicationArray(6) As Book) or Magazine (Public publicationArray(6) As Magazine) I am able to access the properties of that class but not both. I think I need to define a type for each array instance but not sure how to do this.

View 5 Replies

VS 2005 - How To Compare Object Types

Feb 3, 2011

Here's what I'm looking to do. I have an array of objects that all implement a particular interface. What I want to do is search that array of objects for a particular object type.I have to do this in several places, so I'm trying to create a function where I pass in the object array and the type that I'm searching for, and have that function return the object that matches that type - or nothing if no match is found.I wrote the following, but it isn't working, so I'm missing something:

[code]...

View 16 Replies

Checking An Object's Parent Types By String?

Apr 15, 2011

I'm trying to figure out how find an object's type when it is a subclass of another object and I only know the string value of the object's type's name.I created the follwing classes:

HTML

Public Class word
End Class
Public Class noun[code]....

The problem is, using 'GetType' to check pn against a string value, I can only see that pn is a properNoun, not that its parent classes are noun and word.Is there a way to check pn against the string value "noun" or "word" and get back a positive result, indicating that pn is indeed a noun and a word as well as a properNoun?

View 2 Replies

XML Serialization Arraylist With Multiple Object Types?

Feb 10, 2010

My quest is in regards to xml serialization. I need to get rid of the root node of a collection. I don't have access to my source now so I'll just try to generalize

public class SomeClass
'...some other properties...
<XMLArray(isnullable:=true), _
<XMLArrayitem(datatype:=(getType(object1)), _

[code]....

View 6 Replies

Insert Function - Object Cannot Be Cast From DBNull To Other Types

Nov 9, 2011

I am having problems with my code, where I get the "Object cannot be cast from DBNull to other types" message when Insert(). I get the message on every Insert to this table, even though the data is successfully inserted. If I Update the same data after Insert(), it does so without error. I have checked my values and none of them are DBNull. Even when the same values are passed on Insert that are passed on Update.

My code is :
Private Sub Save()
Dim bo As tbl_GL
bo = New tbl_GL()
bo.ConnectionString = AppConfig.ConnectString
[Code] .....

View 4 Replies

C# - From A List<object> , ToString() Them Just When They Are Primitive Types Or Have This Method Overridden??

Feb 15, 2011

Given a list of objects, I'd like to print a string version of them just in case the object.ToString() result is a relevant string.By that I mean I don't want to get things like:

obj.ToString() -> System.Collections.Generic.List`1[MyLib.Dude]
obj.ToString() -> System.Collections.Generic.Dictionary`2[System.Int32,System.DateTime]
obj.ToString() -> System.Byte[]

But I want to get things like:

obj.ToString() -> Hi
obj.ToString() -> 129847.123
obj.ToString() -> Id = 123

What should be the best way to implement this in a method:

Public Sub PrintInterestingStuffOnly(ByVal coolList as Ilist(Of Object))
For Each obj in coolList
'insert solution here

[code].....

View 3 Replies

Runtime Error : Operator '=' Is Not Defined For Types 'Object' And '1-dimensional Array Of DataRow'

Jan 1, 2008

I have set my datasource on my datagridview to be a subset of rows as follows:

dg.DataSource = myDataSet.testTable.Select("id=" & id)

But I get a runtime error that Operator '=' is not defined for types 'Object' and '1-dimensional array of DataRow' There should be an easy way to do this that doesn't involve creating new tables, etc.

View 7 Replies

Cast Value Type To Nullable Enumeration Type In Generic Object If All Types Are Unknown At Write-time?

Dec 14, 2011

I have a generic Class I'm using to hold information loaded from a database.I have a method which takes a DataRow as an argument, uses the object's known column name and extracts the data from the DataRow, such that:Dim loadData As T = CType(myDataRow("myColumnName"), T))works as my default assignment in most cases.Unfortunately, due to some horrifying design constraints, some of my columns may be null, and may also be taken from enumerations.This means that when <T> is Nullable(Of SomeEnumeration) the above code does not work because I can't cast 0 directly to SomeEnumeration.Zero.Is there some way to check whether <T> is Nullable(Of [Enum])? Or some way to write a method which allows Integers to be cast to Nullable(Of [Enum])?I feel like I'm forgetting something that would allow me to write one of the other of these, but my weak google-fu is turning up nothing.

EDIT: Okay, thanks to dasblinkenlight's answer below, I can detect when this circumstance is occurring, but what I need to do now is to take a type <T> which I know is Nullable(Of SomeClass), get a type reference to SomeClass and then create a new object of type Nullable(Of SomeClass) and assign that to LoadData.My problem was that I had a lot of difficulty in finding any function which would accept baseType as an actual Type.Parse accepted baseType as a parameter, I knew baseType was an [Enum] type because of dasblinkenlight's code, so I was, in this instance, able to code a solution. It's a solution which is very specific to my problem (i.e., T is Nullable(of SomeEnumeration)), but it's a solution nonetheless.

View 2 Replies

Troubleshoot "Object Cannot Be Cast From DBNull To Other Types."?

May 1, 2009

how can I troubleshoot "Object cannot be cast from DBNull to other types."?I am using a combobox, to retrieve the price and discount price of the service, If I select an item in combobox3 once, error will not occur, but if I select a item again in combobox3, "Object cannot be cast from DBNull to other types." will occur..here is my code

Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged
Dim ds As New DataSet

[code]....

View 6 Replies

"Object Cannot Be Cast From DBNull To Other Types."?

Jun 20, 2012

how can I troubleshoot "Object cannot be cast from DBNull to other types."?I am using a combobox, to retrieve the price and discount price of the service, If I select an item in combobox3 once, error will not occur, but if I select a item again in combobox3, "Object cannot be cast from DBNull to other types." will occur..

here is my code
Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox3.SelectedIndexChanged

[code].....

View 4 Replies

Add Together Two Nullable Types?

Aug 27, 2010

I have: Dim nVar1 As Long?Dim nVar2 As Long?Dim nVarSum As Long?nVar1 = Nothing nVar2 = 5 nVarSum = nVar1 + nVar2 I would prefer the result to end with nVarSum being 5, instead of Nothing. I understand if you add something to an unknown value, you will end up with "somthing + unknown" or x+5 will always equal "x+5" not "5" because you are still carrying around that unknown "x". However, how can I effectively treat an unknown or Nothing as a zero for the purposes of addition in this case?(What is basically happening is that the end user is sending us a data file, this code parses that file and then sums together about 15 fields. If the user leaves those fields blank instead of assigning a zero to them, I need to treat it as if it was a zero for this one addition operation, but all the rest of the code needs to continue seeing it as a Nothing value since the user did not ACTUALLY submit zero... they submitted blank or nothing)

View 3 Replies

C# - .NET - Custom Types Possible?

Apr 5, 2012

In Delphi you can do something like this :

TArray = array[1..3] of byte;
where you can then declare
T2Array = array[1..3] of TArray

[code].....

View 4 Replies

C# - Built-in Types When (not) To Use?

May 26, 2009

C# and VB.NET comes with built in types that maps to the CLR types. Examples are: int (C#) and Integer (VB) maps to System.Int32, long (C#) and Long (VB) maps to System.Int64. What are the best practices for deciding when to use built in types or not to use them (using the System.* structs/classes instead)?

View 7 Replies

Can Nullable Types Be Used

Jun 27, 2012

Can Nullable Types be used in VB.NET? If so, is it possible to have a Nullable Integer that I can use with a field that accepts NULL in SQL Server?

View 4 Replies

Converting Types Between .Net And VB6?

Jan 7, 2010

Converting types between .Net and VB6?

View 2 Replies

Get Drive Types On Hex Value

Feb 20, 2010

Gota class i'm finishing up to hopefully have as a tutorial on here very soon about working with wndproc in a class for drive readings. Trying to build a simple select state ment for drives removed based off there hexvalue placment so far i've found &H1(Cd devices) and it appears &H0(Usb tho not found other devices to test yet)

[Code]...

View 1 Replies

Have Different Types Of Rectangles?

Mar 8, 2010

I am trying to have different types of rectangles. I thought something like this would work, but Rectangle is not a class.

Public Class xRectangle
Inherits Rectangle
End Class

What I wanted this for was to remove a selection rectangle from an existing drawing. I have all of the objects to draw stored in a list and I am trying to remove the selection rectangle without removing the object it is covering.

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved