Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to get data from my UI and pass it to a class in my class library
this is the code in my UI:
C#
string speech = "WHAT IS UR NAME";
            QuestionAsked question = new QuestionAsked();
            question.GetQuestionAsked = (speech);

Class library
class is QuestionAsked
C#
public  class QuestionAsked
    {
        public string GetQuestionAsked { get; set; }
       
    }

i want to pass that question from my main form to my class in my class library.

What I have tried:

i have tried replacing question.GetQuestionAsked = (speech); with
question.GetQuestionAsked = "WHAT IS UR NAME";
Posted
Updated 13-Jul-19 19:17pm
v3
Comments
OriginalGriff 13-Jul-19 14:14pm    
And? What happened when you did that? What did you expect to happen?

Do you have a question for us?
RickHamton 13-Jul-19 15:28pm    
i expect "GetQuestionAsked" to now contain the same value as speech
RickHamton 13-Jul-19 15:32pm    
i did a break point to check the value change but it still shows the value is null
Richard MacCutchan 13-Jul-19 15:05pm    
There is no such word as "UR".
RickHamton 13-Jul-19 15:29pm    
its not a language you understand bud sorry...

question.GetQuestionAsked = speech;
 
Share this answer
 
Quote:
i expect "GetQuestionAsked" to now contain the same value as speech

i did a break point to check the value change but it still shows the value is null

If you have done this:
string speech = "WHAT IS UR NAME";
QuestionAsked question = new QuestionAsked();
question.GetQuestionAsked = (speech);
Then question.GetQuestionAsked will contain the same value as speech - but only for that one instance. If you create a different instance, it will not contain a value unless you execute similar code on that instance.

Think about cars for a moment - you are driving your car, and you put your mobile in the glove box. Then you buy a new car and drive off in that. Would you expect to find your mobile in the new car's glove box?
Of course not - you understand intuitively that the two vehicles are separate instances of the class "car", and that what you do to a specific instance doesn't affect any other.

It's the same with your QuestionAsked class - what you do to one instance does not affect any other (except with static data, and you'll probably meet that soon).
 
Share this answer
 
Comments
RickHamton 13-Jul-19 16:44pm    
Thanks a lot for the explanation man i will do some research on static data.
can you point me into the right direction? i want to learn how to get data from a user/ UI and pass that data to my class library for processing and then output back to my UI.
A (not static) Class is a blue-print, a plan, a schematic. An instance of a Class is an "object" that implements the plan. You manipulate/use instances of Classes by setting values of fields and Properties, calling/invoking Methods.

You get values/data into an instance of a Class by passing parameters in the constructor of the Class, setting values of fields and Properties, and calling methods, passing parameter values.

A static Class is both a schematic and the one-and--only instance of the Class.
 
Share this answer
 
Comments
RickHamton 29-Nov-19 17:01pm    
wow haven't been back to this post in forever lol i have learnt so much since then.... omg cant believe i even asked such a question lol. sorry for the ancient language guys hopefully you will all learn it one day. THANKS TO ALL THE KIND INDIVIDUALS that actually tried to help though much appreciated.
BillWoodruff 29-Nov-19 23:26pm    
Congratulations ! cheers, Bill

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900