943,587 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 1155
  • C# RSS
Nov 15th, 2008
0

any idea how to assign values to specific variables

Expand Post »
hi

im a noob in C#. just learning by my self. need to know how to assign values to variables. which we input

normally in C we use scanf ne. but in C#. how we gonna assign
Reputation Points: -1
Solved Threads: 4
Junior Poster in Training
lich is offline Offline
78 posts
since May 2008
Nov 15th, 2008
0

Re: any idea how to assign values to specific variables

If you use the console to input data then use

Console.ReadLine() as follow

Say that you want to enter a string

Console.WriteLine("enter your name");
string Name = Console.ReadLine();

Now if you want enter variable other than string

Console.WriteLine("Enter your age");
int Age = Convert.ToInt32(Console.ReadLine());
Reputation Points: 11
Solved Threads: 16
Junior Poster
Jugortha is offline Offline
172 posts
since Oct 2007
Nov 15th, 2008
0

Re: any idea how to assign values to specific variables

superb. let me try it now
Reputation Points: -1
Solved Threads: 4
Junior Poster in Training
lich is offline Offline
78 posts
since May 2008
Nov 15th, 2008
0

Re: any idea how to assign values to specific variables

If you are satisfied please mark the tread as solved

Happy coding
Reputation Points: 11
Solved Threads: 16
Junior Poster
Jugortha is offline Offline
172 posts
since Oct 2007
Nov 15th, 2008
0

Re: any idea how to assign values to specific variables

can you tell me how to put OR in C#
Reputation Points: -1
Solved Threads: 4
Junior Poster in Training
lich is offline Offline
78 posts
since May 2008
Nov 15th, 2008
0

Re: any idea how to assign values to specific variables

I think you should have marked the post solved for him as this is a different question bro

C# conditional OR operator is ||


http://msdn.microsoft.com/en-us/libr...5d(VS.80).aspx
Reputation Points: 155
Solved Threads: 41
Posting Whiz in Training
rapture is offline Offline
294 posts
since Jul 2007
Nov 15th, 2008
0

Re: any idea how to assign values to specific variables

Click to Expand / Collapse  Quote originally posted by lich ...
hi

im a noob in C#. just learning by my self. need to know how to assign values to variables. which we input

normally in C we use scanf ne. but in C#. how we gonna assign
mr.noob i know one way just try it
normally in c we r use scanf()

in C#.net
console.write() write to console and stop
console.writeln() going to next line
console.ReadLine() for user input
Reputation Points: 10
Solved Threads: 1
Newbie Poster
siva_552 is offline Offline
1 posts
since Aug 2008
Nov 15th, 2008
0

Re: any idea how to assign values to specific variables

Beforehand, sorry for my english...
The || - is short version of |.
I.e. if you have simple condition like this:
(a||b) then, there is no difference, what operator to use. In case with complex condition:
((a==b)||(c==d)||(e==f)) will be difference. The || operator will be checking the conditions, untill it find TRUE. If it happened on (a==b), the other conditions will not be checked. If you are choose the | operator, then all conditions will be checked necessarily.
Reputation Points: 293
Solved Threads: 82
Posting Whiz
Antenka is offline Offline
361 posts
since Nov 2008
Nov 16th, 2008
1

Re: any idea how to assign values to specific variables

Quote originally posted by Antenka ...
The || - is short version of |.
That is not quite true, but I realize at first it was fuzzy for myself also.

|| is a conditional OR, it works with booleans : Abool || Bbool, if Abool is true it won't look at Bbool.

| is a bitwise OR it works with booleans and with integral types, it will always perform a bitwise OR on both sides.

Look at this code snippet I found on MSDN(search for C# operators)
C# Syntax (Toggle Plain Text)
  1. class ConditionalOr
  2. {
  3. static bool Method1()
  4. {
  5. Console.WriteLine("Method1 called");
  6. return true;
  7. }
  8.  
  9. static bool Method2()
  10. {
  11. Console.WriteLine("Method2 called");
  12. return false;
  13. }
  14.  
  15. static void Main()
  16. {
  17. Console.WriteLine("regular OR:");
  18. Console.WriteLine("result is {0}", Method1() | Method2());
  19. Console.WriteLine("short-circuit OR:");
  20. Console.WriteLine("result is {0}", Method1() || Method2());
  21. }
  22. }
  23. /*
  24. Output:
  25. regular OR:
  26. Method1 called
  27. Method2 called
  28. result is True
  29. short-circuit OR:
  30. Method1 called
  31. result is True
  32. */
Reputation Points: 2023
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,735 posts
since Oct 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC