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(); 
    } 
}

Recommended Answers

All 7 Replies

Also please tell me about these error.

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

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

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.

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

Wow, just...wow. See that word in your code that says readonly? Make it go away.

Thankkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk youuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
dear deceptikon
now its working

since the problem is solve pls mark it as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.