Click here to Skip to main content
15,884,099 members
Home / Discussions / C#
   

C#

 
Questionlan messenger Pin
rawatsunil9218-Dec-09 22:24
rawatsunil9218-Dec-09 22:24 
AnswerRe: lan messenger Pin
OriginalGriff18-Dec-09 22:35
mveOriginalGriff18-Dec-09 22:35 
AnswerRe: lan messenger Pin
dataminers19-Dec-09 8:04
dataminers19-Dec-09 8:04 
QuestionHow to find the path of a PDF based on corresponding URL opened in IE? Pin
svt gdwl18-Dec-09 19:24
svt gdwl18-Dec-09 19:24 
AnswerRe: How to find the path of a PDF based on corresponding URL opened in IE? Pin
Luc Pattyn19-Dec-09 0:30
sitebuilderLuc Pattyn19-Dec-09 0:30 
Questionhow to write a object data into a file? Pin
santhosh-padamatinti18-Dec-09 19:18
santhosh-padamatinti18-Dec-09 19:18 
AnswerRe: how to write a object data into a file? Pin
dan!sh 18-Dec-09 19:44
professional dan!sh 18-Dec-09 19:44 
AnswerRe: how to write a object data into a file? Pin
OriginalGriff18-Dec-09 22:03
mveOriginalGriff18-Dec-09 22:03 
private void button1_Click(object sender, EventArgs e)
   {
   m_stname = this.textBox1.Text;   
   m_iadminnum = int.Parse(this.textBox2.Text);
   m_sgroup = this.comboBox1.SelectedItem.ToString();

   Form1 f1 = new Form1();

   f1.m_iadminnum = m_iadminnum;
   f1.m_sgroup = m_sgroup;
   f1.m_stname = m_stname;
   }



While what you have will work, it is not exactly a good idea. When you create the new instance of Form1
Form1 f1 = new Form1();
you do not just allocate space for m_stname, m_iadminnum, and m_sgroup, you are also creating new instances of textBox1, textBox2, and comboBox1 as well as a whole load of other stuff you can't see - which is not exactly efficient or usefull.
Consider creating a separate class "StudentInfo" to hold your records, which has the name, admin number, and group. You can then give that class a constructor which takes the three parameters, and a Save/Load method which keeps the data neatly encapsulated.

Additional style points:

1) m_stname, m_iadminnum, and m_sgroup are no longer recommended for C# - consider studentName, adminNumber and studentGroup instead.
2) Don't call you controls by the default name: textBox1 is not as usefull as tbStudentName, button1 is less helpfull than butSave and so on. This may not make a big difference now, but when your app gets more complex (and it will) it makes life a whole lot easier.
3) In your button1_Click event, you do not need to prefix your control names with "this." - it is implied. The only time you should have to use "this" is when you have a parameter with the same name as a field.
4) Unless there is a very good reason for it, make your fields private - you can always add a public property if you need to expose them outside your class.

Trust me, it is worth getting these things right from the start - it is a whole lot easier than breaking bad habits later!

All those who believe in psycho kinesis, raise my hand.

GeneralRe: how to write a object data into a file? Pin
santhosh-padamatinti19-Dec-09 0:13
santhosh-padamatinti19-Dec-09 0:13 
Questionsocket connection when Messenger behind router Pin
s196675m18-Dec-09 13:09
s196675m18-Dec-09 13:09 
AnswerRe: socket connection when Messenger behind router Pin
Migounette18-Dec-09 13:17
Migounette18-Dec-09 13:17 
Questionhow to send mail with hyperlink and values Pin
treuveni18-Dec-09 10:57
treuveni18-Dec-09 10:57 
AnswerRe: how to send mail with hyperlink and values Pin
Stryder_118-Dec-09 11:13
Stryder_118-Dec-09 11:13 
Questionmanipulate the Title of Application [modified] Pin
Terrakotta00118-Dec-09 10:35
Terrakotta00118-Dec-09 10:35 
AnswerRe: manipulate the Title of Application Pin
DaveyM6918-Dec-09 12:09
professionalDaveyM6918-Dec-09 12:09 
QuestionDoes any one know some decent game programming books? Pin
venomation18-Dec-09 10:31
venomation18-Dec-09 10:31 
AnswerRe: Does any one know some decent game programming books? Pin
Migounette19-Dec-09 7:03
Migounette19-Dec-09 7:03 
QuestionNeed help with CPU app Pin
xploda18-Dec-09 8:02
xploda18-Dec-09 8:02 
QuestionVS C# Windows Service - System.IO.DirectoryNotFoundException: Could not find a part of the path Pin
Tomb42118-Dec-09 5:18
Tomb42118-Dec-09 5:18 
AnswerRe: VS C# Windows Service - System.IO.DirectoryNotFoundException: Could not find a part of the path Pin
EliottA18-Dec-09 5:29
EliottA18-Dec-09 5:29 
GeneralRe: VS C# Windows Service - System.IO.DirectoryNotFoundException: Could not find a part of the path Pin
Tomb42118-Dec-09 5:44
Tomb42118-Dec-09 5:44 
GeneralRe: VS C# Windows Service - System.IO.DirectoryNotFoundException: Could not find a part of the path Pin
Luc Pattyn18-Dec-09 5:50
sitebuilderLuc Pattyn18-Dec-09 5:50 
GeneralRe: VS C# Windows Service - System.IO.DirectoryNotFoundException: Could not find a part of the path Pin
Dave Kreskowiak18-Dec-09 6:59
mveDave Kreskowiak18-Dec-09 6:59 
GeneralRe: VS C# Windows Service - System.IO.DirectoryNotFoundException: Could not find a part of the path Pin
Tomb42118-Dec-09 8:14
Tomb42118-Dec-09 8:14 
GeneralRe: VS C# Windows Service - System.IO.DirectoryNotFoundException: Could not find a part of the path Pin
Dave Kreskowiak18-Dec-09 9:30
mveDave Kreskowiak18-Dec-09 9:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.