-1

I have two forms, in the first one, I declared an int variable that should filter the day of a List<DateTime>, for example "Get all the dates that are on wednesday". This int is called WednesdayTotal.

In form1, I placed a label and changed its text by WednesdayTotal value, it displays "2", and I want to use that value in form 2, so the modifier of WednesdayTotal is public, (because its just a test right now), and when I wanted to use it, it displays 0. Why?

Form1 Code:

public int WednesdayTotal;    
WednesdayTotal = DateList.Count(x => x.DayOfWeek == DayOfWeek.Wednesday);

Form2 Code:

if (Home.WednesdayTotal >= 1)
{
    WednesdayPin.Visible = true;
    WednesdayValue.Visible = true;
    WednesdayValue.Text = Home.WednesdayTotal.ToString();
}

In the following line:

  WednesdayValue.Text = Home.WednesdayTotal.ToString();

displays the error:

Warning CS1690 Accessing a member on Form1.WednesdayTotal may cause a runtime exception because it is a field of a marshal-by-reference class

Link Seb
  • 25
  • 5
  • Possible duplicate of [Accessing a member on Form may cause a runtime exception because it is a field of a marshal-by-reference class](https://stackoverflow.com/questions/4178576/accessing-a-member-on-form-may-cause-a-runtime-exception-because-it-is-a-field-o) – Cubemaster Jul 13 '18 at 20:47
  • Capitalizing every word in your first few sentences makes your question hard to read. I've fixed it this time. In the future, please don't do that. –  Jul 13 '18 at 20:48
  • @Link Seb are you using visual studio? – Cubemaster Jul 13 '18 at 20:49

1 Answers1

0

If you are using visual studio, there is a quick and easy fix for this:

  1. Press Ctrl + Alt + E to open the exception settings.
  2. Uncheck the Box labeled "Managed Debugging Assistants"

This should stop you from seeing the warning. If you actually want to fix the warning, for some reason, I can only direct you to here

Cubemaster
  • 507
  • 1
  • 6
  • 20