Skip to content

Please rectify this C# error I tried using google also.

Par ma

Asked Nov 10, 2017, 11:46 PM ESTSolved
Share
LinkedInX
C#
using System;
using System.Collections.Generic;
namespace GenericApplication
{
public class MyGenericApplication<T>
{
private T[] array;
public static MyGenericArray(int size)
{
return MyGenericArray[size];
}
public T getItem(int index)
{
return array[index];
}
public void setItem(int index,T value)
{
return array[index]=value;
}
}
class tester
{
public static void Main(string[]args)
{
MyGenericArray<int> intArray=new MyGenericArray<int>(5);
for (int c=0;c<5;c++)
{
intArray.setItem(c,c*5);
}
for (int c=0;c<5;c++)
{
Console.Write(intArray.getItem(c)+" ");
}
Console.WriteLine();
MyGenericArray<char> charArray=new MyGenericArray<char>(5);
for (int c=0;c<5;c++)
{
charArray.setItem(c,(char)(c+97));
}
for (int c=0;c<5;c++)
{
Console.Write(charArray.getItem(c)+" ");
}
Console.WriteLine();
}
}
}
main.cs(8,16): error CS1520: Class, struct, or interface method must have a return type



3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • ✓ Accepted answer0
    using System;
    using System.Collections.Generic;
    namespace erro
    {
    public class MyGenericApplication<T>
    {
    public T[] array=new T[5];
    public T MyGenericArray(int size)
    {
    return MyGenericArray(size);
    }
    public T getItem(int index)
    {
    return array[index];
    }
    public T setItem(int index, T value)
    {
    return array[index] = value;
    }
    }
    class tester
    {
    public static void Main(string[] args)
    {
    int[] c1 = new int[5];
    MyGenericApplication<int> intt = new MyGenericApplication<int>();
    for (int c = 0; c < 5; c++)
    {
    intt.setItem(c, c * 5);
    }
    for (int c = 0; c < 5; c++)
    {
    Console.Write(intt.getItem(c) + " ");
    }
    Console.WriteLine();

    for (int c = 0; c < 5; c++)
    {
    intt.setItem(c,(c + 97));
    int i=intt.getItem(c);
    char chara = (char)i;
    Console.Write(chara + " ");
    }
    for (int c = 0; c < 5; c++)
    {
    Console.Write(intt.getItem(c) + " ");
    }
    Console.WriteLine();
    Console.ReadLine();
    }
    }
    }
    0
  • 0
    Hi Parma
    You Are having error on 8th row here "public static MyGenericArray(int size)".
    You made it static thats y you getting error.
    0
  • 0
    can you explain in detail what you want to do with your code.
    0