DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C# (http://www.daniweb.com/forums/forum61.html)
-   -   any idea how to assign values to specific variables (http://www.daniweb.com/forums/thread157483.html)

lich Nov 15th, 2008 1:54 am
any idea how to assign values to specific variables
 
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

Jugortha Nov 15th, 2008 6:14 am
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());

lich Nov 15th, 2008 10:47 am
Re: any idea how to assign values to specific variables
 
superb. let me try it now :D

Jugortha Nov 15th, 2008 10:52 am
Re: any idea how to assign values to specific variables
 
If you are satisfied please mark the tread as solved

Happy coding

lich Nov 15th, 2008 11:30 am
Re: any idea how to assign values to specific variables
 
can you tell me how to put OR in C#

rapture Nov 15th, 2008 1:23 pm
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

siva_552 Nov 15th, 2008 1:30 pm
Re: any idea how to assign values to specific variables
 
Quote:

Originally Posted by lich (Post 736469)
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

Antenka Nov 15th, 2008 7:00 pm
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.

ddanbe Nov 16th, 2008 7:36 am
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)
class ConditionalOr
{
    static bool Method1()
    {
        Console.WriteLine("Method1 called");
        return true;
    }

    static bool Method2()
    {
        Console.WriteLine("Method2 called");
        return false;
    }

    static void Main()
    {
        Console.WriteLine("regular OR:");
        Console.WriteLine("result is {0}", Method1() | Method2());
        Console.WriteLine("short-circuit OR:");
        Console.WriteLine("result is {0}", Method1() || Method2());
    }
}
/*
Output:
regular OR:
Method1 called
Method2 called
result is True
short-circuit OR:
Method1 called
result is True
*/


All times are GMT -4. The time now is 9:49 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC