You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- A method identifier is used as if it were a struct or class
22
22
23
-
## Example
23
+
## Examples
24
+
25
+
### Example 1
24
26
25
27
The following sample generates CS0119: 'C.B()' is a method, which is not valid in the given context. You can fix this error by changing the name of the method `C.B`, or using the fully qualified name for the class `B` like `N2.B`.
26
28
@@ -42,3 +44,70 @@ namespace N1
42
44
}
43
45
}
44
46
```
47
+
48
+
### Example 2
49
+
50
+
The following sample shows a common scenario where CS0119 occurs when trying to add class names to a collection of types. The compiler expects <xref:System.Type> instances, not class names.
51
+
52
+
```csharp
53
+
usingSystem;
54
+
usingSystem.Collections.Generic;
55
+
56
+
publicclassPage_BaseClass { }
57
+
publicclassPage_CRTable { }
58
+
publicclassPage_DBGridWithTools { }
59
+
60
+
publicstaticclassPageTypeManager
61
+
{
62
+
publicstaticList<Type> GetPageTypes()
63
+
{
64
+
List<Type>pageTypesList=newList<Type>();
65
+
66
+
// CS0119: 'Page_BaseClass' is a type, which is not valid in the given context
67
+
pageTypesList.Add(Page_BaseClass);
68
+
pageTypesList.Add(Page_CRTable);
69
+
pageTypesList.Add(Page_DBGridWithTools);
70
+
71
+
returnpageTypesList;
72
+
}
73
+
}
74
+
```
75
+
76
+
To fix this error, use the <xref:System.Type.GetType%2A?displayProperty=nameWithType> method or the `typeof` operator to get `Type` instances:
0 commit comments