0

I am beginner in for c#
Please help me for compilation of this code. Also please tell me about these error.
Thanks

using System; 

class SearchEmp 
{ 
    String[] Name= {"Aslam","Irfan","Afridi","Junaid"}; 

    SearchEmp(string name){ 
        this.name = name; 
    } 

    public void Search(){ 
        name= "Afridi"; 
        if(Name[0]==name||Name[1]==name||Name[2]==name||Name[3]==name){ 
            Console.WriteLine("FOUND"); 
        } 
    } 
    private readonly string name; 

    public static void Main(){ 
    SearchEmp E1= new SearchEmp("Kareem"); 
    E1.Search(); 
    } 
}
3
Contributors
7
Replies
10
Views
4 Years
Discussion Span
Last Post by otengkwaku
0

Also please tell me about these error.

You forgot to list the errors, and your title for this thread is uninformative.

Edited by deceptikon

0

Error

Compiling the source code....
$/usr/local/bin/mcs /tmp/135963473426049/csharp135963473426049.cs 2>&1
/tmp/135963473426049/csharp135963473426049.cs(12,3): error CS0191: A readonly field `SearchEmp.name' cannot be assigned to (except in a constructor or a variable initializer)
Compilation failed: 1 error(s), 0 warnings
0

A readonly field `SearchEmp.name' cannot be assigned to

So...what does that tell you? It's not like the error is ambiguous or unclear. SearchEmp.name is defined as readonly, yet you try to assign to it as if it were not readonly.

0

please tell me how i can correct it?
or please correct that code and post here
i am not good with programming

0

Thankkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk youuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
dear deceptikon
now its working

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.