如何在System.Numerics.BigInteger中向BigInteger类添加定义 [英] how to add a definition to a BigInteger class in System.Numerics.BigInteger

查看:186
本文介绍了如何在System.Numerics.BigInteger中向BigInteger类添加定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI
我是c#编码的新手。目前使用System.Numerics.BigInteger中的BigInteger类编码RSA-1024算法,现在我需要一个函数来生成随机素数。我正在使用visual studio 4.0。我有BigInteger类但没有生成素数的定义。我有一个函数定义,我需要的是在System.Numerics中添加到BigInteger类中



任何人都可以帮助这个

提前感谢

HI i am a newbee in coding with c#. presently coding RSA-1024 algorithm using BigInteger class from System.Numerics.BigInteger, where now i need a function to generate random prime numbers. i am using visual studio 4.0. i have the BigInteger class but no defintion for the generating prime. i have a function defintion for it, all i need is to add into that BigInteger class in System.Numerics

can anyone help with this
thanks in advance

推荐答案

你不能直接修改基本Biginteger类。



但是,你可以在这个类上创建一个扩展方法;这样:

You cannot directly modify the base Biginteger class.

But, you can create an extension method on this class ; this way:
using System.Numerics;

public static class Extensions
{
   public static int GenerateRandomPrimeNumber(this Biginteger bi)
   {
      // Your logic goes here
   }
}



用于:


For the usage:

Biginteger bi = BigInteger.Zero;
int myPrime = bi.GenerateRandomPrimeNumber();





警告:扩展方法适用于实例,这就是为什么我必须声明一个BigInteger变量才能访问GetRandomPrimeNumber()扩展方法。如果您没有原始源代码并且可以重新编译,则无法在类本身上创建静态方法。



Warning: extension methods work on instances, that's why I had to declare a BigInteger variable to get access to the GetRandomPrimeNumber() extension method. You cannot create a static method on the class itself if you do not have the original source code and can recompile.


这篇关于如何在System.Numerics.BigInteger中向BigInteger类添加定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆