C
C#2y ago
bixen7135

Issue

Error CS0116 The namespace cannot be implemented in elements such as methods or operators.
11 Replies
Angius
Angius2y ago
Namespace cannot contain fields Only classes can
Honza K.
Honza K.2y ago
move it into the class, c# is not c++, it cannot have members outside class and class must be inside a namespace
bixen7135
bixen7135OP2y ago
Can I have a code example where is it correct?
Angius
Angius2y ago
$structure
MODiX
MODiX2y ago
namespace Namespace;

[Attribute]
public class Class
{
public string PublicField;
private bool _privateField;
protected double protectedField;

public int PublicProperty { get; set; }

public Class() {} // Constructor

public void Method(int parameter)
{
var localVariable = parameter;
}
}
namespace Namespace;

[Attribute]
public class Class
{
public string PublicField;
private bool _privateField;
protected double protectedField;

public int PublicProperty { get; set; }

public Class() {} // Constructor

public void Method(int parameter)
{
var localVariable = parameter;
}
}
For C# versions older than 10, see $StructureOld
Angius
Angius2y ago
Here's an example of a proper structure $structureold
MODiX
MODiX2y ago
namespace Namespace
{
[Attribute]
public class Class
{
public string PublicField;
private bool _privateField;
protected double protectedField;

public int PublicProperty { get; set; }

public Class() {} // Constructor

public void Method(int parameter)
{
var localVariable = parameter;
}
}
}
namespace Namespace
{
[Attribute]
public class Class
{
public string PublicField;
private bool _privateField;
protected double protectedField;

public int PublicProperty { get; set; }

public Class() {} // Constructor

public void Method(int parameter)
{
var localVariable = parameter;
}
}
}
For C# versions from 10 onwards, see $structure
Angius
Angius2y ago
Here it is with the oldschool style namespaces
Honza K.
Honza K.2y ago
bixen7135
bixen7135OP2y ago
Why in this place i have a problem?
Angius
Angius2y ago
There's no OleDbConnection class If it's inside of some library or a different namespace in general, you need to import it with a using statement Use the quick fixes and VS can do it for you
Want results from more Discord servers?
Add your server