473,396 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

very simple loop with strange output

I now know that I know nothing...

using System;
using System.IO;

namespace ADODotNet
{ public class Class1
{ public Random r = new Random();
string[] nodes = new string[] { "192.168.0.0", "192.168.0.1",
"192.168.0.2", "192.168.0.3", "192.168.0.4", "192.168.0.5",
"192.168.0.6", "192.168.0.7", "192.168.0.8", "192.168.0.9" };
public TextWriter tw = new StreamWriter("c:\\populate.txt");
[STAThread]
public static void Main()
{ Class1 mc = new Class1();
for (int i = 0; i <= 299; i++) //mornin
mc.putIP();
}
public void putIP()
{ tw.Write(nodes[r.Next(10)]);
tw.Write(" , ");
tw.Write(tw.NewLine);
}
}
}

I thought I'd get 300 lines but instead I get 256...why

Apr 24 '06 #1
5 1177
Try a tw.Flush() after the for(). Does that help?

--
William Stacey [MVP]

<bo****@yahoo.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
|I now know that I know nothing...
|
| using System;
| using System.IO;
|
| namespace ADODotNet
| { public class Class1
| { public Random r = new Random();
| string[] nodes = new string[] { "192.168.0.0", "192.168.0.1",
| "192.168.0.2", "192.168.0.3", "192.168.0.4", "192.168.0.5",
| "192.168.0.6", "192.168.0.7", "192.168.0.8", "192.168.0.9" };
| public TextWriter tw = new StreamWriter("c:\\populate.txt");
| [STAThread]
| public static void Main()
| { Class1 mc = new Class1();
| for (int i = 0; i <= 299; i++) //mornin
| mc.putIP();
| }
| public void putIP()
| { tw.Write(nodes[r.Next(10)]);
| tw.Write(" , ");
| tw.Write(tw.NewLine);
| }
| }
| }
|
| I thought I'd get 300 lines but instead I get 256...why
|
Apr 24 '06 #2
Error 1 An object reference is required for the nonstatic field,
method, or property 'ADODotNet.Class1.tw' C:\Documents and
Settings\me\Local Settings\Application Data\Temporary
Projects\Project1\CodeFile1.cs 18 13 Project1..........................wont
let me use tw in Main....im extremely new to c#

Apr 24 '06 #3
nevermind it worked!!!thanks a million...what was wrong

Apr 24 '06 #4
In Main:

mc.FlushMe();

then write the method

public void FlushMe()
{
this.tw.Flush();
}

Apr 24 '06 #5
<bo****@yahoo.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
Error 1 An object reference is required for the nonstatic field,
method, or property 'ADODotNet.Class1.tw' C:\Documents and
Settings\me\Local Settings\Application Data\Temporary
Projects\Project1\CodeFile1.cs 18 13
Project1..........................wont
let me use tw in Main....im extremely new to c#


Main is a static function so does not have access to any module variables in
your class. A static function is just like a global function but placed in
your class for readability.

Michael
Apr 24 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: hall | last post by:
Hi. I've come across someting strange. I was trying to make a for-loop execute repetadly until the function called inside it does not return true during the entire loop (see program below). ...
6
by: leonecla | last post by:
Hi everybody, I'm facing a very very strange problem with a very very simple C program... My goal should be to write to a binary file some numbers (integers), each one represented as a sequence...
6
by: m_a_t_t | last post by:
Ok, I'm reading "The C Programming Language: 2nd Edition" and I'm on chapter 1.5.1 and here's the program you're sposed to make: #include <stdio.h> /* copy input to output; 1st version */...
2
by: Alex | last post by:
Compiler - Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland Linker - Turbo Incremental Link 5.65 Copyright (c) 1997-2002 Borland Platform - Win32 (XP) Quite by accident I stumbled...
2
by: TB | last post by:
I am seeing a very strange problem as follows... I have a loop where a fair amount of processing is going on and near the top of the loop I access a class that has only static helper functions...
5
by: cody | last post by:
I have a very funny/strange effect here. if I let the delegate do "return prop.GetGetMethod().Invoke(info.AudioHeader, null);" then I get wrong results, that is, a wrong method is called and I...
14
by: dba_222 | last post by:
Dear experts, Again, sorry to bother you again with such a seemingly dumb question, but I'm having some really mysterious results here. ie. Create procedure the_test As
11
by: VijaKhara | last post by:
Hi all, I just write a very simple codes in C and vthere is a very strange bug which I cannot figure out why. The first loop is for v, and the second for k. There is no relationship between v...
4
by: maria | last post by:
I only use C++ with Visual Studio 6.0 for string manipulations in thousands of HTML pages on my website. Many times, the output files of many of my C++ programs contain a spanish question mark (¿)...
1
by: jerry | last post by:
i have written a simple phonebook program,i'll show you some of the codes,the program's head file is member.h . i suppose the head file works well.so i don't post it. here's the clips of main...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.