2
Answers

GetHashCode() method

Maha

Maha

12y
1.2k
1

http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/system-object-a-look-on-mother-of-all-managed-classes/

Normally Student student = new Student();


In this program Student student = new Student { RollNumber = "1" }; I couldn't understand this. Any ones knows please explain.

using System;

namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{

Student student = new Student { RollNumber = "1" };

int hash1 = student.GetHashCode();

Console.WriteLine(hash1);

Console.ReadKey(true);
}
}

class Student
{
public string RollNumber { get; set; }
public string Name { get; set; }

public override int GetHashCode()
{
//return base.GetHashCode();
return Convert.ToInt32(RollNumber) * 100;
}
}
}

Answers (2)