samedi 25 avril 2020

A field initializer cannot reference the nonstatic field, method, or property in loginController

i am beginner in c# MVC and i write a class randomGenarator to generate random number

 public class RandomGenarator
{

    public int rand()
    {
        Random rnd = new Random();
        int  i = rnd.Next(100);
        return i;
    }
}

but when i tried to use that in My Controller class

 public class LoginController : Controller
{ 
    RandomGenarator rnd = new RandomGenarator();
    int i = rnd.rand();

    public ActionResult Index()
    {

        return View();
    }

i faced with this Error: "A field initializer cannot reference the nonstatic field, method, or property"

please Help ME




Aucun commentaire:

Enregistrer un commentaire