|
I have a notepad text file that looks like this:
xxxxixxxxxcxxxxxxxxixxxxt
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
25 across, 19 down...
And some code to read in the text file:
FileStream fs = File.OpenRead("maptest.txt");
StreamReader reader = new StreamReader(fs);
string x = string.Empty;
while (!reader.EndOfStream)
{
int y = reader.Read();
char z = (char) y;
if (z == 'x' || z == 'c' || z == 'i' || z == 't') x += z.ToString();
}
char[,] map = new char[25, 19];
int index = 0;
for (int row = 0; row < 25; row++)
{
for (int col = 0; col < 19; col++)
{
map[row, col] = x[index];
index++;
}
}
My array "char[,] map = new char[25, 19]" is meant to store x and y cords of each character ie to find the first instance of the character "i" I can get its by referencing "map[4,0]".
My text reader is wrong and I need some help to read in the values into the array
|
|
|
|
|
Actually, don't you want the array to be [19,25], as in 19 rows of 25 characters ?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hey Mark, why do all your posts get a 1 vote? Does someone here hate you?
|
|
|
|
|
Yes, there appears to be very childish people around here. What a surprise.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
You have your columns and rows mixed up.
char[,] map = new char[25, 19];
int index = 0;
for (int row = 0; row < 19; row++)
{
for (int col = 0; col < 25; col++)
{
map[col, row] = x[index];
index++;
}
}
|
|
|
|
|
Thanks all works now
|
|
|
|
|
On an unrelated matter, why are you making a string that way?
You could use a StringBuilder, or even skip that step at all if you're only using it to fill the map (you could fill the map directly)
In this case it doesn't matter that much since the string is fairly short, but string concatenation inside a loop should generally be avoided..
|
|
|
|
|
If you create a custom collection by deriving from CollectionBase, is there an easy way to fire an event when one of the collection items is updated?
For example, any GUIs that care can subscribe to some sort of event that would be fired where an object that is a member of the collection is modified?
|
|
|
|
|
If you have created a custom class you can create whatever events make sense. For instance, in your override for the OnSet method fire off your custom event.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Not that I know of. There are two easy options.
1. If you are using .NET framework 3.5 then add a reference to WindowsBase to your project. You can then use System.Collections.ObjectModel.ObservableCollection<T> which has an event CollectionChanged which should do what you want.
2. Make your own generic class and implement ICollection<T> and possibly ICollection . You can simply wrap a List<T> in this class to make implementation easier. Now you have control over all items in/out of the collection so can raise custom events as you like.
[Edit]
I've just had a look at the CollectionBase class and you should be able to override the necessary methods as they are protected virtual and raise your own event(s).
OnClear, OnInsert, OnRemove, OnSet
All these also have a protected virtual OnxxxComplete method too.
[/Edit]
Dave
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
modified on Sunday, March 21, 2010 10:09 AM
|
|
|
|
|
hello
can any one give me a sample code of
creating a function or procedure in oracle
and then use it to return a datatable with tableadapter
thank you
|
|
|
|
|
Here[^]
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Dear Friend,
I am working on GridView in c#. Getting a problem on dynamic add html in a GridView Columns. How can I make a dynamic template by coding??? Many thanks.
<br />
<br />
DataTable dt = new DataTable();<br />
dt.Columns.Add("Id", Type.GetType("System.Int32"));<br />
dt.Columns.Add("Detail", Type.GetType("System.String"));<br />
<br />
dr = dt.NewRow();<br />
dr["Id"] = id;<br />
dr["Detail"] = "<a href='home.aspx#" + id + "' >Detail</a>";<br />
dt.Rows.Add(dr);<br />
<br />
gridView.DataSource = dt;<br />
gridView.DataBind();<br />
|
|
|
|
|
Use a HyperLinkField;
HyperLinkField detailLink = new HyperLinkField();
detailLink.NavigateUrl = string.Format("home.aspx#{0}", id);
detailLink.Text = "Detail";
gridView.Columns.Add(detailLink);
You will also need to set the AutoGenerateColumns to false and create a BoundField for the id column.
|
|
|
|
|
FileSecurity ACL = File.GetAccessControl(InputFile);
ACL.AddAccessRule(new FileSystemAccessRule("Guest", FileSystemRights.Delete, AccessControlType.Deny));
ACL.AddAccessRule(new FileSystemAccessRule("SYSTEM", FileSystemRights.Delete, AccessControlType.Deny));
ACL.AddAccessRule(new FileSystemAccessRule("Administrators", FileSystemRights.Delete, AccessControlType.Deny));
ACL.AddAccessRule(new FileSystemAccessRule("Users", FileSystemRights.Delete, AccessControlType.Deny));
File.SetAccessControl(InputFile, ACL);
Im using the above code in a loop to server to stop files from being deleted from my RAID (Nothing critical just Movies) but it seems to make flip all difference apart from the flag in special permissions (Which means the ACL is being applied) setting the read-only property to true doesn't help either.
Can anyone suggest a solution ? AFIK the above should cover all users.
|
|
|
|
|
This will control access from within your managed application but will do nothing for another application or an unmanaged app.
What is causing the delete?
You could possibly use a service that instantiates a FileSystemWatcher and monitors for the delete event
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
No not other applications just the operating system and shares via the context menu or the delete button.
Basically i want the directories to remain untouched so any device can add files to the share but every file on the raid to be read only / undeletable.
AFIK i did the equivalent of this on my old nas (777 folders 755 files) so files can e added but not removed.
|
|
|
|
|
BuggingMe wrote: No not other applications just the operating system
So an OS is not a collection of applications ?
Your RAID setup should be configurable for this.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
3ware 9500S-12 in RAID5, I haven't come across any such setting in the cards bios or webgui. Surely there must be some method to stop files being deleted in the operating system
|
|
|
|
|
I am planning to generate 8 to 15 reports in sql server report server 2008. I want to create 8 to 15 separate sql server reports and tie them together with a table of contents in a c#.net 2008. I then want to export these reports into an electronic format to email to users.
Can I setup separate sql server report service files (rdls) and have the C#.NET application tie these files together? I am hoping I can export the reports to Word.
Can you give me suggestions on how to accomplish this task?
|
|
|
|
|
I have an application that users collect data using a webbrowser control and a paser behind it to collect the data. When complete, users login in to a central site and we post the data collected.
We have a clever user that has changed their hosts file to redirect the posting to a server they hosted where they then have access to the data.
We are going to go with an SSL approach, but I need to make sure when we post the data that we are posting to the correct server and not a server someone has spoofed by changing their hosts file to point to a different server.
We'd like to be able to establish a SSL connection to our server and validate the certificate in code. We are using the webbrowser control and I am not sure how to access the certificate so that we can see if we are indeed connected to the correct server.
Any hints on how I might do this or where I might look?
|
|
|
|
|
Hi,
I have an abstract class like this:
public abstract class Component
{
private static readonly Dictionary<string, Type> RegisteredProperties
= new Dictionary<string, Type>();
public static void RegisterComponent(Type propertyType)
{
RegisteredProperties.Add(nameAttribute.Name, propertyType);
}
}
I then derive a group of classes from Component , like so:
public class StandardTimeComponent : Component
{
static StandardTimeComponent()
{
RegisterComponent(typeof(DateTime.StartProperty));
RegisterComponent(typeof(TimeZone.OffsetToProperty));
}
}
public class NonStandardTimeComponent : Component
{
static StandardTimeComponent()
{
RegisterComponent(typeof(DateTime.StartProperty));
RegisterComponent(typeof(TimeZone.OffsetToProperty));
}
}
I then discovered that if both classes are instantiated, I get an exception as the static constructor tries to add the same key to dictionary twice. The static field is shraed by both inheriting classes.
Thinking about it, this makes sense. So, my question is, is there a way to define a Dictionary so that it is statically available in the Base class, but such that StandardTimeComponent.RegisteredProperties is different to NonStandardTimeComponent.RegisteredProperties? Any suggestions or suitable Google terms (I drew a blank ) would be most appreciated.
Edit : Fixed the angle brackets for the Dictionary generics.
|
|
|
|
|
what is static in a base (or abstract) class, is shared by all its instances, both direct and inherited instances.
what is static in a derived class, is shared by instances of that class only, hence:
- move your dictionary to each of the derived classes;
- pass it on as a parameter to the methods that need it (RegisterComponent in the base class).
|
|
|
|
|
Do you really need to be able to inherit from the base class? If not you can make it non-abstract and generic. That way any instance of the class with the same type will share same dictionary and every other type will have its own dictionary.
|
|
|
|
|
The key is "nameAttribute.Name" which "is unique to each propertyType". Change it that it is unique to each combination of class and propertytype.
|
|
|
|