Error cs1061 как исправить

This repository contains .NET Documentation. Contribute to dotnet/docs development by creating an account on GitHub.

Permalink

Cannot retrieve contributors at this time

description title ms.date f1_keywords helpviewer_keywords

Compiler Error CS1061

Compiler Error CS1061

05/01/2021

CS1061

CS1061

Compiler Error CS1061

‘type’ does not contain a definition for ‘name’ and no accessible extension method ‘name’ accepting a first argument of type ‘type’ could be found (are you missing a using directive or an assembly reference?).

This error occurs when you try to call a method or access a class member that does not exist.

Example

The following example generates CS1061 because Person does not have a DisplayName method. It does have a method that is called WriteName. Perhaps that is what the author of this source code meant to write.

public class Person
{
    private string _name;

    public Person(string name) => _name = name;

    // Person has one method, called WriteName.
    public void WriteName()
    {
        System.Console.WriteLine(_name);
    }
}

public class Program
{
    public static void Main()
    {
        var p = new Person("PersonName");

        // The following call fails because Person does not have
        // a method called DisplayName.
        p.DisplayName(); // CS1061
    }
}

To correct this error

  1. Make sure you typed the member name correctly.
  2. If you have access to modify this class, you can add the missing member and implement it.
  3. If you don’t have access to modify this class, you can add an extension method.

See also

  • The C# type system
  • Extension Methods

  • Remove From My Forums
  • Question

  • Hi Everyone,

    I have an error message when I try to run my program, this is error CS1061 like show below. But actually my program is success full to run before.. But I don’t know why suddenly when I try to compile there’s any error :  

    —— Build started: Project: Latihan1, Configuration: Debug x86 ——

    c:userslinadocumentsvisual studio 2010ProjectsLatihan1Latihan1Form1.Designer.cs(40,55): error CS1061: ‘Latihan1.Form1’ does not contain a definition for ‘Form1_Load’ and no extension method ‘Form1_Load’ accepting a first argument of type ‘Latihan1.Form1’
    could be found (are you missing a using directive or an assembly reference?)

    Compile complete — 1 errors, 0 warnings

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Answers

  • It looks like you accidentally created a form Load event handler, then deleted it from code, but not the designer. To fix:

    Open up your form in the designer, and go to the events in the properties page.  Delete the «Form1_Load» event on the form’s Load…


    Reed Copsey, Jr. — http://reedcopsey.com
    If a post answers your question, please click «Mark As Answer» on that post and «Mark as Helpful«.

    • Marked as answer by

      Saturday, November 26, 2011 6:25 AM

Ошибка в unity: error CS1061

Здраствуйте!
имеется скрипт для пули:

Используется csharp

using UnityEngine;
using System.Collections;

public class Vistrel : MonoBehaviour {
        // Use this for initialization
        void Start () {

       
        }

       
        // Update is called once per frame
        void Update () {

       
        }
void OnTriggerEnter(Collider col)//Заметь, что в col хранится информация о коллайдере, который вошел в триггер, через него мы можем получить ссылку на объект
{
        if(col.gameObjext.tag==«Enemy»)//делаем проверку на тэг, чтобы случайно не отправить сообщение о дамаге стене.
        {
                col.gameObject.SendMessage(«TakeDamage»,50);
        }
}
}

В консоле видаёт ошибку на этот скрипт:
Assets/scripts/Vistrel.cs(16,16): error CS1061: Type `UnityEngine.Collider’ does not contain a definition for `gameObjext’ and no extension method `gameObjext’ of type `UnityEngine.Collider’ could be found (are you missing a using directive or an assembly reference?)

Кто знает что делать и как исправить?

Аватара пользователя
Dragon-FAST
UNIт
 
Сообщения: 92
Зарегистрирован: 15 авг 2016, 08:29

Re: Ошибка в unity: error CS1061

Сообщение waruiyume 19 авг 2016, 04:04

gameObjext

Аватара пользователя
waruiyume
Адепт
 
Сообщения: 6059
Зарегистрирован: 30 окт 2010, 05:03
Откуда: Ростов на Дону

Re: Ошибка в unity: error CS1061

Сообщение Dragon-FAST 19 авг 2016, 06:03

waruiyume писал(а):gameObjext

Спасибо видать просто допустил опечатку…

Аватара пользователя
Dragon-FAST
UNIт
 
Сообщения: 92
Зарегистрирован: 15 авг 2016, 08:29


Вернуться в Скрипты

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 9



AssetsRoomSpawner.cs(35,58): error CS1061: ‘GameObject[]’ does not contain a definition for ‘Lenght’ and no accessible extension method ‘Lenght’ accepting a first argument of type ‘GameObject[]’ could be found (are you missing a using directive or an assembly reference?)это ошибка полностью

помогите пожалуйста разобраться.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RoomSpawner : MonoBehaviour
{
public Direction direction;

public enum Direction
{
Top,
Bottom,
Left,
Right,
None
}

private RoomVariants variants;
private int rand;
private bool spawned = false;
private float waitTime = 3f;

private void Start()
{
variants = GameObject.FindGameObjectWithTag(«Rooms»).GetComponent<RoomVariants>();
Destroy(gameObject, waitTime);
Invoke(«Spawn», 0.2f);
}
public void Spawn()
{
if (!spawned)
{
if(direction == Direction.Top)
{
rand = Random.Range(0, variants.topRooms.Lenght);
Instantiate(variants.topRooms[rand], transform.position, variants.topRooms[rand].transform.rotation);
}
else if(direction == Direction.Bottom)
{
rand = Random.Range(0, variants.bottomRooms.Lenght);
Instantiate(variants.bottomRooms[rand], transform.position, variants.bottomRooms[rand].transform.rotation);
}
else if(direction == Direction.Right)
{
rand = Random.Range(0, variants.rightRooms.Lenght);
Instantiate(variants.rightRooms[rand], transform.position, variants.rightRooms[rand].transform.rotation);
}
else if(direction == Direction.Left)
{
rand = Random.Range(0, variants.leftRooms.Lenght);
Instantiate(variants.leftRooms[rand], transform.position, variants.leftRooms[rand].transform.rotation);
}
spawned = true;
}
}
private void OnTriggerStay2D(Collider2D other)
{
if(other.CompareTag(«RoomPoint») && other.GetComponent<RoomSpawner>().spawned)
{
Destroy(gameObject);
}
}
}

Понравилась статья? Поделить с друзьями:
  • Error cs1031 требуется тип
  • Error cs1026 юнити
  • Error cs1026 unexpected symbol expecting
  • Error cs1026 expected unity
  • Error cs1024 требуется директива препроцессора