none
Working with class atributes RRS feed

  • Question

  • Ok.. I thought that i know working with classes, but now when i have simple problem i do not know how to solve it...

    My project have two forms and i whant to transfer some entered data from Form 1 to Form 2, and oposite...And i whant to use class as a bridge for that transfering.I know that there is a solution with Form contructor  but i whant to use class. forms have two buttons and two textboxes

    Question :how to define class that can save changed atribut from one form, and use that info for form 2.Becouse when i create in form 2 , contructor for class, it set defoult value..Not value that i entered from form 1. :(

    my class looks like :

    public  class Class1
        {
          public static string jezik = "Test";

    }

    so, additional information: i whant when i create contructor from form1:

    Class1 cls=new Class();

    and set jezik to:  cls.jezik="New Test";

    and when i create that class from form 2:

    Class1 cls1=new Class();

    textBox.text=cls1.jezik; //// to bee stored in text box "New test", not old "Test"

    is there even possible, that class saves last changed information of its atribute??

    Thanks anyway :)

    Wednesday, December 26, 2012 12:53 PM

Answers

  • Hi Baturanija,

    Welcome to the MSDN Forum.

    The quick answer is Yes. And you don't need to create an instance because you just use the static property jezik, and it can be accessed by Class name rather than instance.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 27, 2012 6:02 AM
    Moderator

All replies

  • Hi Baturanija,

    Welcome to the MSDN Forum.

    The quick answer is Yes. And you don't need to create an instance because you just use the static property jezik, and it can be accessed by Class name rather than instance.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 27, 2012 6:02 AM
    Moderator
  • Great...i did not try to do this: Class1.jezik="New Test"...So that is working..Thanks man ...Love VS2010
    Thursday, December 27, 2012 12:14 PM