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

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How do I generate a hashcode from a object array in c#

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :.NET Framework

Hi All,

I'm using code below for generate a hashcode, but i think it's not good solution...

static int GetHashCode(ICollection c)
      StringBuilder sb = new StringBuilder();

      foreach (object o in c)

      return sb.ToString().GetHashCode();

What do you think about this?

View Complete Post

More Related Resource Links

Converting ReportDocument object into byte array ?


Hi All,

          Is it possible to convert the Report Document object as a byte array and store it in SQL , later retrieve and assing it to a report ?


How to: Serialize Hashtable contained inside another object that is serialized as an array of object

Update:  I've added the entire program in a single block of C# text near the end of these posts that can be placed into a C# Program.cs file of a console project.   I have a class called MyHashtable that inherits from Hashtable and implements IXmlSerializable.  MyHashtable is contained inside another object called MyObject and I need to xml serialize an array of MyObject[].  Whenever I xml deserialize, the hashtable is deserialized, but only 1 of MyObjects from the MyObject[] array is deserialized.  The ReadXml uses "while (reader.NodeType != XmlNodeType.EndElement)" so I don't think the reader is consuming all of the xml internally.   Does anyone know why this is happening?  Thanks.    

How to create an extremely large array/object (> 2 GB) without using jagged arrays ?

Hello,I had implemented a matrix scaling algorithm in Java (64-bit) for a university project and have now implemented the code in C# with .NET 3.5 64-bit. One of the operations I did in Java was creating a rectangular array with double[][] = ... (in C# this is a jagged array!) to store a symmetric matrix which is used as input for the algorithm. Since I was using matrices with n up to 30720, memory usage for the single matrix object was around 8 GB in it's maximum and with matrix multiplication around 20 GB.So... now I implemented this in C# and I am shocked to see that double[,] (rectangular arrays) can only be 2 GB in size even on 64-bit! That means that for matrices with n larger than ~15000 I will get OutOfMemory Exceptions although there is a huge amount of free memory (I have two quad core systems with 12 GB and 24 GB Ram). When I use jagged arrays in C# (i.e. double[][]) I can create larger matrices. That is because I have one small array with the size of the row number (i.e. n) and then for each row an array of size n, but they are all single objects so I don't reach the 2 GB per object limit. The problem with jagged arrays is that they are horribly slow for matrice calculations compared to rectangular arrays and even slower compared to single dimension arrays.Actually I intended to rewrite my code and simulate the matrices in single arrays (see sample code below) bec

Converting a System.Windows.Control.Image object to byte array.

Hi i need to convert a specific System.Windows.Control.Image object into an (int) array, because i'm trying to convert a silverlight application into a wpf project. private void createGi02GradBrush()<br/> {<br/> WriteableBitmap oWriteableBitmap = new WriteableBitmap(256, 256);<br/> Image oImage = new Image();<br/> oImage.Arrange(new Rect(0, 0, 256, 256));<br/> oImage.Measure(new Size(256, 256));<br/> oImage.Source = new WriteableBitmap(256, 256);<br/> Gi02GradShaderEffect oGi02GradShaderEffect = new Gi02GradShaderEffect();<br/> oGi02GradShaderEffect.pArray = oPImageBrush;<br/> oGi02GradShaderEffect.gi1GradArray = oGi1GradImageBrush;<br/> oImage.Effect = oGi02GradShaderEffect;<br/> oWriteableBitmap.Render(oImage, null);//here<br/> oWriteableBitmap.Invalidate(); <br/> this.oGi02GradImageBrush = new ImageBrush();<br/> this.oGi02GradImageBrush.ImageSource = oWriteableBitmap;<br/> } I've found some similar topics however Image object is not the same and most of its methods aren't available. Here I'm rendering a writablebitmap with a given Image object, but in wpf we need an array. oWriteableBitmap.Render(oImage, null); Any idea? Thanks. Joseph.  

how to query return all data in Array Object ,Collection Object

how to query return all data in Array Object ,Hash Table ,And DataTable dataRowSelect * From Doc a

Converting an Image/BitmapImage object into Byte Array and vice versa

Hi,  I have an requirement of developing an application (WPF) that recevies image object from WCF service.

my approch is to convert the image object into stream of bytes (Byte array) in WCF part and then send to  client application. Then client application converts the byte array back to image object.

I am not able to find right sample for my approach.

would you give me guidance and would be gr8 if you provide some samples.


Error: Object reference not set to an instance of an object for an array in vb.net


I have the following code

Dim ls_case_no() As String = Nothing
 Dim li_case_count As Integer = 0

  Dim li_case As String = ""
         li_case = xmlLocNode.InnerText
                                            If Not li_case = "" Then
                                                'li_case = li_case.Replace("-", "")
                                                ls_case_id = li_case

                                                ReDim Preserve ls_case_no(li_case_count)
                                                li_case_count = li_case_count + 1
                                                ls_case_no(li_case_count - 1) = ls_case_id
                                            End If

 myNode = xmlLocNode.SelectSingleNode("nc:CaseTrackingID", nsMgr)
                                             If Not myNode.InnerText = "" Then
                                                Dim li_case As String = myNode.InnerText
                                               lbl_caseno.Text = li_case
                                                ls_case_core = li_case
                                            End If

 If Not ls_case_no.Length = 0 Then
            For d = 0 To ls_case_no.Length - 1
                If Not ls_case_no(d) = ls_case_core Then

Expeting array of object instead of arraylist


Hi all..

  i have an method in wcf which takes ArrayList object in parameter and returns an arraylist object.

 There s no problem here...

  But in client application that method expects array of objects instead of arraylist...

  how to solve this problem...

how do you get object array number in a method?


Lets say you have four array objects.

test[1] = new test();

test[2] = new test();

test[3] = new test();

test[4] = new test();

then you have your class:

public class test()


   public int i; //initialize some fields

   public int getnumber()


  // what is the array number of the this object? 1, 2, 3, or 4???



so basically, if an object is called: test[1].getnumber   how can this method internally determine what object array number it is currently in?  (without passing an integer from the page)

  it can be either 1, 2,3, or 4.

How to auto-generate object initzializer code according to any given class definition?



I think this is at least somewhat connected to reflection so I posted it here.

I work with WCF and Web Services right now. Of course I use the tools provided to generate code from the WSDL documents, hence, for every datatype, a corresponding class is generated. As the WS has loads of types with nested subtypes, I get about 80 usually small classes, only having a few members. In order to implement all that, I have to initialize the classes over and over again.

So I wonder, if there is no way, to use reflection to automatically generate  code (object inizializer) from the class definition, including all subclasses?

Ideal would be a snipped - so that I just enter the name of any random class and dynamically get the full initializer generated. Do snippets actually have the power to do that?

As this will save a lot of stupid typing, I also wonder, if there aren't already any tools, snippets or widgets that do this? I assumed that is is something many programmers might need, but google did not show anything like it.

Thank you very much!

How to generate MySite Usage Report using Sharepoint Object Model


Hi All,

In my Portal i have MySites some where around 15000 where in every day i need to auto generate MySites usage report in excel format.

Can some one please help me out how to acheive the same using Sharepoint Object Model.

NullReferenceException in array? Object reference not set to an instance of an object.


I am receiving a NullReferenceException, but I can not find where it is.

The code:

string[] strAccount = null;
DateTime[] dtFirstPurchDate = null;
DateTime[] dtLastPurchDate = null;
TimeSpan[] dtFirstLastPurchDiff = null;


//Start iterating through the original gridview with line item totals
for (int i = 0; i <= GridViewECI.Rows.Count-1; i++)


if (i == 0)
//set first gridview records so we can use it to review next lines of data

                   strAccount[counter] = GridViewECI.Rows[i].Cells[0].Text;
                    dtFirstPurchDate[counter] = DateTime.Parse(GridViewECI.Rows[i].Cells[1].Text);

<-- error occurs here at dtFirstPurchDate with Object reference not set to an instance of object

Sending js Array object in jQuery Ajax post

The article Sending js Array object in jQuery Ajax post was added by tmorton on Thursday, May 12, 2011.

The post name should be "Serializing to JSON in jQuery" or something like that but I kind of twisted it the way I faced this issue. If you're looking for how to do the ajax calling in jQuery and blah da. then you should keep googling cause this post ain

Thinking about new C# method prototypes: object as dictionary

I recently had to write a small Flickr API. I know many .Net API for Flickr already exist but I needed one for a Silverlight application. Whatever, it's only about building some querystrings so I did it by myself. It's been an opportunity to think again about a classical question: how to pass parameters to a method ?

Imagine you have a generic method to call some Flickr functions.

C# Object Oriented Programming

So far in C# Essentials we have looked at the basics of programming in C# such as variable types and flow control. Although it would be possible to write a functional program using these techniques, there is much more to becoming a proficient C# programmer. C# is, above all, an object oriented programming language and as such any C# programmer will be expected to create object-oriented applications using this language.

Object Oriented Programming

Four core concept of OOP Object Oriented Programming. 1.Inheritance, 2.Polymorphism, 3.Abstraction and 4.Encapsulation

Object-Oriented Programming Concepts

This is the first in a series of articles describing the use of object-oriented programming techniques as implemented by the C# programming language. This series follows the C# Fundamentals tutorial that beginners are advised to read first.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

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