2013-06-24 41 views
-3

我應該編輯下面的接口實現類,但我不知道該怎麼做。沒有必要編輯界面?我如何提供該類來實現?我不知道如何填寫構造函數和convertToLower()接口實現C#

public interface DenemeInterface 
{ 
    string convertToLower(); 
} 

public class Deneme : DenemeInterface 
{ 
    public Deneme(string s) 
    { 
    } 

    public string convertToLower() 
    { 
     return ""; 
    } 
} 
+3

你的問題是什麼? –

+1

'我不知道如何填充構造函數和converttoLower()'。你是什​​麼意思?該接口定義了一個返回字符串的無參數方法。實現此接口的類必須具有一個具有相同名稱和相同返回類型的無參數方法。 –

+0

爲您提供實現的框架,您的任務是做實際的實現。如果您需要幫助完成作業,則需要顯示它。另外,如果你需要幫助完成任務,你應該在問題中清楚地說明,這樣我們就可以幫助你瞭解你需要知道的內容。 – Guffa

回答

1

我想,我終於明白你正在試圖做

試試這個什麼:

public interface DenemeInterface 
{ 
    string convertToLower(); 
} 
public class Deneme : DenemeInterface 
{ 
    string a; 
    public Deneme(string s) 
    { 
     this.a = s; 
    } 

    public string convertToLower() 
    { 
     return a.ToLower(); 
    } 
} 

你問我的意見i wrote that string a=s; inside Deneme(string s) constructor but i cant use that variable which is name "a" inside convertToLower(). How can i store the value provided in the constructor

您需要在構造函數之外聲明它,否則它將僅在構造函數中可用。

+0

他們的工作非常感謝 –

0

您已經在實現該接口。你在這裏這樣做:

public class Deneme : DenemeInterface 

它基本上讀取「Deneme類實現DenemeInterface」。 當然,接口本身需要一個名爲convertToLower()的方法來返回一個字符串。但你已經有了。你已準備好出發。需要注意的是接口通常以'I'開頭,考慮將其更改爲IDenemeInterface。

-Edit AHHH。我認爲康拉德是正確的。在這種情況下,你會想是這樣的:

public interface IDenemeInterface 
{ 
    string convertToLower(); 
} 

public class Deneme : IDenemeInterface 
{ 
    private string s; 

    public Deneme(string s) 
    { 
     this.s = s; 
    } 

    public string convertToLower() 
    { 
     return this.s.ToLower(); 
    } 
} 
+0

他們的工作表示感謝 –