Search Results

Search found 2 results on 1 pages for 'daemonfire3002nd'.

Page 1/1 | 1 

  • C# : Console.Read() does not get the "right" input

    - by Daemonfire3002nd
    Hi there, I have the following code: The actual problem is the "non-quoted" code. I want to get the player amount (max = 4), but when I ask via Console.Read() and I enter any Int from 1 to 4 I get as value: 48 + Console.Read(). They only thing how I can get the "real" input is using Console.ReadLine(), but this does not give me an Integer, no it returns a string, and actually do not know how to convert String (Numbers) to Integers in C#, because I am new, and because I only found ToString() and not ToNumber. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace eve_calc_tool { class Program { int players; int units; int active_units; int inactive_units; int finished_units; int lastDiceNumber = 0; bool game_state; public static void Main(string[] args) { int count_game = 0; //Console.Title = "Mensch ärger dich nicht"; //Console.WriteLine("\tNeues Spiel wird"); //Console.WriteLine("\t...geladen"); //System.Threading.Thread.Sleep(5000); //Console.Clear(); //Console.WriteLine("Neues Spiel wird gestartet, bitte haben sie etwas Geduld"); //Console.Title = "Spiel " + count_game.ToString(); //Console.Clear(); //string prevText = "Anzahl der Spieler: "; //Console.WriteLine(prevText); string read = Console.ReadLine(); /*Program game = new Program(); game.players = read; game.setPlayers(game.players); if (game.players > 0 && 5 > game.players) { game.firstRound(); }*/ string readagain = read; Console.ReadLine(); } /* bool setPlayers(int amount) { players = amount; if (players > 0) { return true; } else { return false; } } bool createGame() { inactive_units = units = getPlayers() * 4; active_units = 0; finished_units = 0; game_state = true; if (game_state == true) { return true; } else { return false; } } int getPlayers() { return players; } private static readonly Random random = new Random(); private static readonly object syncLock = new object(); public static int RandomNumber(int min, int max) { lock (syncLock) { // synchronize return random.Next(min, max); } } int rollDice() { lastDiceNumber = RandomNumber(1,6); return lastDiceNumber; } int firstRound() { int[] results = new int[getPlayers()]; for (int i = 0; i < getPlayers(); i++) { results[i] = rollDice(); } Array.Sort(results); return results[3]; } */ } }

    Read the article

  • Manipulating existing XDocument (fails)

    - by Daemonfire3002nd
    Hi there, I got the following Code snippet from my Silverlight Application: var messages = from message in XcurrentMsg.Descendants("message") where DateTime.Parse(message.Attribute("timestamp").Value).CompareTo(DateTime.Parse(MessageCache.Last_Cached())) > 0 select new { ip = message.Attribute("ip").Value, timestamp = message.Attribute("timestamp").Value, text = message.Value, }; if (messages == null) throw new SystemException("No new messages recorded. Application tried to access non existing resources!"); foreach (var message in messages) { XElement temporaryElement = new XElement("message", message.text.ToString(), new XAttribute("ip", message.ip.ToString()), new XAttribute("timestamp", message.timestamp.ToString())); XcurrentMsg.Element("root").Element("messages").Add(temporaryElement); AddMessage(BuildMessage(message.ip, message.timestamp, message.text)); msgCount++; } MessageCache.CacheXML(XcurrentMsg); MessageCache.Refresh(); XcurrentMsg is a XDocument fetched from my server containing messages: Structure <root> <messages> <message ip="" timestamp=""> Text </message> </messages> </root> I want to get all "message" newer than the last time I cached the XcurrentMsg. This works fine as long as I cut out the "XElement temporaryElement" and the "XcurrentMsg.Element...." and simply use the currentMsg string as output. But I want to have "new messages" being saved in my XcurrentMsg / Cache. Now if I do not cut this part out, my Application gets awesome crazy. I think it writes infinite elements to the XcurrentMsg without stopping. I can not figure out what's the problem. regards,

    Read the article

1