2013-11-04 12 views
10

"AppendText" असाइन नहीं कर सकता क्योंकि यह एक "विधि समूह" है।असाइन नहीं किया जा सकता क्योंकि यह एक विधि समूह सी # में है?

public partial class Form1 : Form 
{ 
    String text = ""; 

    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     String inches = textBox1.Text; 
     text = ConvertToFeet(inches) + ConvertToYards(inches); 
     textBox2.AppendText = text; 
    } 

    private String ConvertToFeet(String inches) 
    { 
     int feet = Convert.ToInt32(inches)/12; 
     int leftoverInches = Convert.ToInt32(inches) % 12; 
     return (feet + " feet and " + leftoverInches + " inches." + " \n"); 
    } 

    private String ConvertToYards(String inches) 
    { 
     int yards = Convert.ToInt32(inches)/36; 
     int feet = (Convert.ToInt32(inches) - yards * 36)/12; 
     int leftoverInches = Convert.ToInt32(inches) % 12; 
     return (yards + " yards and " + feet + " feet, and " + leftoverInches + " inches."); 
    } 
} 

त्रुटि लाइन "textBox2.AppendText = पाठ", button1_Click विधि के अंदर चल रहा है।

+1

धन्यवाद दोस्तों। क्षमा करें अगर मैं इतना मूर्ख था :( – puretppc

+0

उह मैंने कोशिश की और यह काम किया लेकिन किसी कारण से, यह इसे एक नई लाइन में प्रदर्शित नहीं करेगा। – puretppc

+2

क्या टेक्स्टबॉक्स में 'मल्टीलाइन = ट्रू' है? अगर लोगों में से एक नीचे आपके प्रश्न का उत्तर देते हैं, कृपया – Basic

उत्तर

19

उपयोग एक संपत्ति है, लेकिन एक तरीका नहीं है। इस प्रकार इसे पैरामीटर के साथ बुलाया जाना चाहिए और सीधे असाइन नहीं किया जा सकता है।

गुण विशेष विधियां हैं, जो संकलक में विशेष हैंडलिंग के कारण असाइनमेंट का समर्थन करती हैं।

3

इस बजाय करते हैं (AppendText एक विधि, नहीं एक संपत्ति है, जो है कि वास्तव में क्या त्रुटि संदेश आपको बता रहा है):

textBox2.AppendText(text); 
3

textBox2.AppendText(text); एक method है। आपको इसे एक जैसा कॉल करना होगा। आप एक विधि पर एक असाइनमेंट ऑपरेशन कर रहे थे। निम्नलिखित

textBox2.AppendText(text); 

textBox2.AppendText = text; 

AppendText के बजाय

3

आप इस तरह से AppendText कॉल करनी होगी:

textBox1.AppendText("Some text") 
3

AppendText एक तरीका है और आप इसे कॉल करना होगा।

textBox2.AppendText(text); 
संबंधित मुद्दे