Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"A namespace cannot directly contain members such as fields or methods" [closed]

I am trying to use this code for NET.reflector using Reflexil. I am trying to replace code with this:

if(Input.GetKeyDown(KeyCode.Keypad5)) {  int i = 0;  Character localPlayer = PlayerClient.GetLocalPlayer().controllable.GetComponent<Character>();  foreach (UnityEngine.Object obj2 in UnityEngine.Object.FindObjectsOfType(typeof(LootableObject)))  {      if (obj2 != null)      {          i++;          LootableObject loot = (LootableObject) obj2;          Debug.Log("Loot "+i+": "+loot.transform.position.ToString());          CCMotor ccmotor = localPlayer.ccmotor;          if(ccmotor != null && tpPos1 != Vector3.zero) {              ccmotor.Teleport(loot.transform.position);              Notice.Popup("", "Teleported to "+loot.name, 1.5f);          }          break;      }  }  

}

But it gives me an error when I try to compile:

Line: 1 Column: 1 Error Number: CS0116  Error Message: "A namespace does not directly contain members such as fields or methods" 

This is Unity code I think. I am not that experienced. Could anyone fix this for me? Or tell me what to do? Thanks!

like image 832
user3204732 Avatar asked Jan 17 '14 00:01

user3204732


People also ask

What does error cs0116 mean?

A namespace cannot directly contain members such as fields or methods.

What is a namespace in C#?

The namespace keyword is used to declare a scope that contains a set of related objects. You can use a namespace to organize code elements and to create globally unique types. C# Copy.


1 Answers

The snippet you're showing doesn't seem to be directly responsible for the error.

This is how you can CAUSE the error:

namespace MyNameSpace {    int i; <-- THIS NEEDS TO BE INSIDE THE CLASS     class MyClass    {       ...    } } 

If you don't immediately see what is "outside" the class, this may be due to misplaced or extra closing bracket(s) }.

like image 55
G. Stoynev Avatar answered Sep 28 '22 02:09

G. Stoynev