public String In_Box_Check(object Object_Name) // Проверка поля на наличие в них данных { string Status = "Incorrect"; if (Object_Name.Text != "") { Status = "Correct"; } return Status; } 

The line with if not executed. Writes that the Object has no text property. I tried to put Value - the same result. What to do?

  • one
    As the type of Object_Name specify its real type (which, in particular, has the Text property). And System.Object really does not have such a property - VS doesn't lie to you. - Regent
  • I pass a textbox to this function: In_Box_Check (Chanel_CBox) - George Tuzikov
  • So, in the method parameters, indicate that Object_Name is a TextBox , and not just some abstract object . - Regent
  • 3
    Then, probably, the type Control - the parent for all components - will do. By the way, is it WinForms or WPF? Add a tag. - Alexander Petrov
  • one
    @GeorgeTuzikov then Control ObjectName . At least you will have access to .Text . - Regent

1 answer 1

For understanding.

Writes that the Object has no text property.

Here, for some reason, is the object data type, but it is not universal

All classes in the c # language are inherited from the System.Object class (you can just write object ). It defines literally two or three methods - and all descendants of this class have them (read, all classes in your project). These are ToString , Equals , GetType and ... some more.

This class has no fields and properties. Totally.

Therefore, your attempt to access some property is expected to cause an error at the compilation stage, namely at the stage of accessing the property. Due to the fact that any class is a descendant of System.Object it can be reduced to a base type and passed to a method.

Therefore, the decision in the comments you were offered a completely natural and logical: correctly specify the name of the class that you pass.