Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Общие вопросы по .NET и C# > Возращать значение?


Автор: Elfet 24.8.2005, 18:33
Код

        class BoxInt
        {
            public BoxInt(int max)
            {
                i = new int();
                from[] = new int[max];
                to[] = new int[max];

                i = 0;
            }
            private string[] from;
            private string[] to;
            private int i;
            public SetReplace(string from, string to)
            {
                this.from[this.i] = from;
                this.to[this.i] = to;
                this.i++;
            }
        }


Не хочет работать smile Почему?

Цитата
error CS1520: Class, struct, or interface method must have a return type

Автор: arilou 24.8.2005, 18:39
Код

public SetReplace(string from, string to)


Как насчет
Код

public void SetReplace(string from, string to)


?

Автор: Elfet 24.8.2005, 19:00
Код

        class BoxInt
        {
            public BoxInt(int max)
            {
                i = new int();
                from = new string[max];
                to = new string[max];

                i = 0;
            }
            private string[] from;
            private string[] to;
            private int i;
            public void SetReplace(string from, string to)
            {
                this.from[this.i] = from;
                this.to[this.i] = to;
                this.i++;
            }
        }


О smile Заработал! Спасибо!

Автор: Elfet 24.8.2005, 19:18
Нет не заработал smile Вот что говорит:
Цитата
tick-tack-toe\Form1.cs(270): 'tick_tack_toe.Form1.BoxInt.Change(int)': not all code paths return a value

А что это значит я не могу понять smile

Код

        class BoxInt
        {
            public BoxInt(int max)
            {
                i = new int();
                from = new string[max];
                to = new string[max];

                i = 0;
            }
            private string[] from;
            private string[] to;
            private int i;
            public void SetReplace(string from, string to)
            {
                this.from[this.i] = from;
                this.to[this.i] = to;
                this.i++;
            }
            public string Change(int str)//вот тут что-то не нравится
            {
                for(int i=0; i < this.i; i++)
                {
                    if(this.from[i] == str.ToString())
                        return this.to[i];
                }
            }
        }



Автор: Дрон 24.8.2005, 21:50
Цитата(Elfet @ 24.8.2005, 20:18)
public string Change(int str)//вот тут что-то не нравится
            {
                for(int i=0; i < this.i; i++)
                {
                    if(this.from[i] == str.ToString())
                        return this.to[i];
                }
            }

Так он же пишет, что ему не нравится: не все пути возвращают значение smile
Т.е. если у тебя вдруг this.i <= 0 или не найдётся ни одного from[i] который совпадёт с str, то какое значение он должен вернуть??

Автор: Guest 25.8.2005, 09:55
Дрон
О ну надоже заработало! smile Спасибо!

Автор: Competitor 26.8.2005, 08:36
А про приведение типов забыл?

Автор: Mad 6.9.2005, 02:56
Цитата(Elfet @ 24.8.2005, 18:00)
  i = new int();

а это уже полное изврашение smile
int это value type соответственно место под него выделяетьсяпри обьявленииб конечно можно и новой выделить, просто попробуй инту null присвоить ;).

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)