You cannot use a local variable before it is declared by ASP.NET.

I have a code like this:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Save([Bind(Prefix="")]Person person)
{
    String s = person.property;
    /* ... */
}

But he gives an error: "You can not use the local variable" person "before its declaration."

What simple thing am I missing?

+3
source share
3 answers

Well, this is just some really strange mistake - if a variable is called by a specific name, it does not work, for any other name it works ...

+3
source

Most likely, you get this error because the same variable is declared later in the same code block.

, .

, , ( ) .

+13

finalYear.

:

        public ChartData(MetricInfo metricInfo, MetricItem[] metricItems) : this()
        {
            int endingYear = 0;

:

            endingYear = endingDate.Year;

Case, " ", intelesense:

                case "QRTR_LAST_FULL_QRTR":
                    if (metricInfo.CalendarType == "CALENDAR")
                    {
                        switch (endingDate.Month)
                        {
                            case 1:
                            case 2:
                            case 3:
                                loopControl = 4;
                                endingYear = endingDate.Year - 1;

Matt, endYear, . . , , , .

+2

Source: https://habr.com/ru/post/1699393/


All Articles