Thread: some super basic questions ٩(-̮̮̃ -̃)۶

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    13

    some super basic questions ٩(-̮̮̃ -̃)۶

    Hello every1 <3

    Hopefully I can bother some with some q's... I apologize in advance if they are a tad easy or a tad too many (since I wanted to avoid making so many threads). Anyhow, thanks for any help on ANY questions! Just ignore a question if you don't feel like answering it, as I'm grateful for any feedback. Sorry for any incoherence as well; I did solve many things with Google, but I can't seem to find details on a few, sadly (although I'll keep trying). Much obliged!





    1) In C++, system("pause") is used to pause programs (although I believe some would say this is bad practice but anyhow); so in C#, does
    Code:
     Console.ReadLine();
    used for this role? Unfortunately, my manual doesn't really go over this basic fact.


    2) is an extra Console.ReadLine(); needed for a block of if-else statements? (I don't see how else to system pause).


    3) How else can I skip a line? Use an empty Console.WriteLine(); or Console.WriteLine("my text \n"); ?


    4) Saw this in a textbook:
    Code:
    Console.WriteLine("My name is (0)", myString);
    Isnt the placeholder supposed to use braces, not parentheses?



    5) Are custom (i.e. your created) namespaces necessary for simple programs?


    6) Are Console.WriteLine(w.GetType()); or Char.IsLetter(yourChar) methods?



    7) Does it matter that char.IsLetter(yourChar) uses a lower case c?


    8) Is string.Format like ToString? Why not use writeline?



    9) Saw this in a text book as well.
    Code:
     // Check for equality:
    isEqual = (a == b);
    Console.WriteLine("BTW, the equality is: {0}.", isEqual );
    Is isEqual missing a bool ? (I couldn't compile otherwise)


    10) Is there an alternative to
    Code:
     string theNumber = Console.ReadLine();
    Is our input strictly regarded as strings, or char with casting?



    11) After multiple using multiple sources, I can't seem to differentiate heap from stack. Any tips?


    12) Finally, for
    Code:
     // Hexadecimal:
    Console.WriteLine("0x{0:x}",0x15 | 0x4); // 0x15
    Console.WriteLine("0x{0:x}",0x15 & 0x4); // 0x4
    // Decimal:
    Console.WriteLine(21 | 4); // 21
    Console.WriteLine(21 & 4); // 4
    What is going on here? I do recognize 0:x as a hexadecimal conversion, but I'm not sure what the Bitwise Operators are or what they're doing... (¬_¬")



    I apologize again, and I appreciate you taking the time to read this. Cheers!

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    1)
    If you want to effectively pause the execution until the user performs some action, then Console.ReadLine() is the most effective way. Especially if you place it after Console.Write("Press Enter to continue..."), or Console.WriteLine("Paused. Press Enter to continue..."). Console.ReadLine() is the preferred method for controlling the console execution. There's another approach involving the Thread class. But I think it's best you ignore that for now.

    3)
    Your choice. There's also Console.WriteLine("my text" + "\n"). which I tend to prefer because it makes the "\n" more visible when writing several WriteLine() in block. But this is largely a matter of preference.

    4)
    You are correct. That will not work as the person writing that is expecting.

    5)
    Nope.

    6)
    Of course.

    7)
    As far as the compiler is concerned, no. As far as you are concerned, a little. It's important to adopt consistency throughout. You can name that type in 3 ways: System.Char, Char and char. Try to stick to one. My C++ background forces me to always use the lowercase form for any intrinsic type. Your background may hint you otherwise, which is fine. Just stick to the same formula.

    8)
    No. String.Format can be helpful if you want to write a formatted string to memory and only use it later, or use it by other means than WriteLine(), like printing it or sending it to a text box.

    9)
    Yes. It is possible the author forgot to declare the variable.

    10)
    See the Parse() and TryParse() methods of the numeric types. For instance, int.Parse()

    11)
    This one deserves a different thread. Start one and tells us about what you have learned, or think have learned so far.

    12)
    Someone is apparently being ridiculous and messing with the reader head. Just ignore anything from that person and look for another book/website.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    41
    3) Console.WriteLine() already has a 'newline' appended to whatever text you give it. Adding '\n' to it would make it perform two newlines. Also, if you want your code to work everywhere, don't use '\n' for newline, use Environment.NewLine (as in "Console.Write(Environment.NewLine);"). This will ensure that a proper newline is performed (some systems use '\r\n' for a newline, this way you don't care).

    12) The first is displaying the results in hex, the second in decimal. The '|' operator is the or operator. So in the example we have 0x15 (which is 21 decimal) or binary 10101. We are doing a bitwise or with 0x4 (binary 00100) which gives us this:
    10101
    00100
    -------
    10101 ('|' says if either or both are 1, then 1 else 0).

    The second is an 'and ' which gives:
    10101
    00100
    ------
    00100 ('and' says if both are 1 then 1 else 0).

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by Momerath View Post
    some systems use '\r\n' for a newline, this way you don't care).
    That would be Windows, but the console, ascii documents and printers understand "\n" just fine. This is a non issue under Windows. "\n" will only become a problem on any Macintosh before MacOS X (that's any macintosh 10 years old or more). Macs now use LF just like any Unix brand, so "\n" is how Environment.NewLine is defined for them.

    In any case I agree Environment.NewLine is the correct way if one plans to port to other systems.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #5
    Registered User
    Join Date
    May 2011
    Posts
    13
    thanks a ton, everyone!
    2) as far as I can tell, you do need it, whether you have else-if statements or nested if-else (interestingly, the author refers to the former as "nested")
    11) will review more on that one
    12) yes, I'm still not too sure about these bitwise operations (but I'll check out its wikipedia article) and maybe then I can understand the logic better... at least I learnt that decimal also refers to base 10, as opposed to what people generally refer to
    0) in the meantime, trying to get my headers to work ;>
    again, you've all been a great help!

  6. #6
    Registered User
    Join Date
    May 2011
    Posts
    13
    3) oh I think I realized what the zeroes and ones are... its basic logic... that would explain the operators

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. super basic question about boolean evaluation
    By rodrigorules in forum C++ Programming
    Replies: 7
    Last Post: 02-20-2011, 04:48 AM
  2. Basic Questions
    By Panda_ in forum C Programming
    Replies: 15
    Last Post: 09-23-2009, 04:24 PM
  3. Super newbie questions
    By Need_O2 in forum C++ Programming
    Replies: 28
    Last Post: 04-16-2008, 07:35 AM
  4. hello. basic questions
    By johnnyboy in forum C++ Programming
    Replies: 14
    Last Post: 02-01-2008, 10:58 AM
  5. basic questions on C#
    By black in forum C# Programming
    Replies: 3
    Last Post: 12-09-2003, 09:23 AM