Interface

Multiple inheritance is not supported by c#. Instead of that we use interfaces for avoiding ambiguity in C++ , where the object of the class doesn’t know which method to call if the base classes have two methods of the same name.
interfaces are defined in parent and implemented by derived class it have indexers, methods and properties.

for example:


interface Newinterface
{
void Mymethod();
}

interfaces are declared with keyword 'Interface' .

using System;

interface BaseInterface
{
void BaseToImplemen();
}

interface Childinterface:  BaseInterface
{
void childToImplement();
}

class Newchild : Childinterface
{
static void Main()
{
InterfaceImplementer iImp = new InterfaceImplementer();
iImp.childToImplement();
iImp.BaseToImplemen();
}

public void childToImplement()
{
Console.WriteLine("childToImplement() called.");
}

public void BaseToImplemen();
{
Console.WriteLine("BaseToImplemen();called.");
}
}

Advertisement

2 Responses to Interface

  1. alka says:

    hi,

    i am creating a web page using master pages. in my default.aspx page i have a textbox, a button , a fileupload control
    and a drop down. fileupload is hidden . i want taht when i click on button control ——– fileupload clicked automatic
    and the selected path is shown is textbox control after that a function is called that fill the drop down .

    in aspx page :

     

    in aspx.cs page

    protected void Button6_Click(object sender, EventArgs e)
    {
    Type cty=this.GetType();
    System.Text.StringBuilder script = new System.Text.StringBuilder();
    string fileID = FileUpload2.ClientID;
    string pathtext = TextBox1.ClientID;
    script.Append(“”);
    script.Append(“document.getElementById(‘”);
    script.Append(fileID);
    script.Append(“‘).click();”);
    script.Append(“document.getElementById(‘”);
    script.Append(pathtext);
    script.Append(“‘).value=”);
    script.Append(“document.getElementById(‘”);
    script.Append(fileID);
    script.Append(“‘).value;”);
    script.Append(“”);
    ClientScript.RegisterStartupScript(cty, “scriptpage”, script.ToString());
    callfill();
    }

    public void callfill()
    {
    OleDbConnection conn = getconnection();
    String[] item = getSheetName(conn);
    //for (int i = 0; i < item.Length; i++)
    //{
    // DropDownList1.Items.Add(item[i].ToString());
    //}
    //}

    private String getFileName()
    {
    //Response.Write("aaa" +TextBox1.Text);
    //return "a";
    return TextBox1.Text;
    }

    private OleDbConnection getconnection()
    {
    string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + getFileName() + ";Extended Properties=Excel 8.0";
    return new OleDbConnection(connString);
    }

    but getfilename method is not able to read textbox1 value.
    please tell a solution of it.

    thanks
    Alka

    • venkatu2005 says:

      use viewState to hold the filename acrosspostback

      so viewState["filename"] = Textbox1.Text;

      and pass the viewstate directly on your query..
      ie: Viewstate["filename"].ToString()

      I think this may help you../

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.