3
Answers

Override Methods

Photo of Arezoo Sh

Arezoo Sh

13y
1.7k
1
Hi,

I want to override these methods below of Random Class. I know haow can I override a method but there is a problem here! We dont have the codes of virtual methods below in MSDN to change them and make override methods.

methods: DoubleByte, NextByte, Next, ToString

forexample: I want to override NextByte method of Random class. The NextByte method returns an array contain random numbers. now the method that I want to override NextByte method, should be like the NextBytes method with some changes, forexample what? could u help me to write override methods above?

Answers (3)

0
Photo of Vulpes
NA 98.3k 1.5m 13y
If you're going to derive from the Random class and override the methods you've listed, then I'd take a look at the underlying code first.

This can be revealed using a disassembler such as Redgate Reflector (http://reflector.red-gate.com/download.aspx?TreatAsUpdate=1) which is no longer free or JetBrains dotPeek (http://www.jetbrains.com/decompiler/) which is free but hasn't yet reached version 1.0.
0
Photo of Jaganathan Bantheswaran
NA 21.9k 2.2m 13y
Hi,

Its better to know how to override a method in C#.

to override the NextByte,

define a method like this with virtual keyword in the class you want to use.
public virtual void NextBytes(byte[] buffer)
{
        // your code here
}



0
Photo of Jiteendra Sampathirao
NA 6.9k 1.5m 13y