|

<pre>
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Applica
{
class Program
{
static void Main(string[] args)
{
DirectoryInfo da = new DirectoryInfo("C:\\Folder");
FileInfo[] Arr = da.GetFiles();
if (Arr.Length == 0)
{
throw new InvalidOperationException("No files found.");
}
FileInfo ap = Arr[Arr.Length - 1];
long Totbyte = ap.Length;
string filePath = ap.FullName;
Console.WriteLine("Total Bytes = {0} bytes", Totbyte);
string temPath = Path.GetTempFileName();
byte[] data = File.ReadAllBytes(filePath);
File.WriteAllBytes(temPath, data);
string arry = ASCIIEncoding.ASCII.GetString(data);
Console.WriteLine(arry);
byte[] data2 = Encoding.ASCII.GetBytes(arry);
foreach (byte element in data2)
{
Console.WriteLine("{0}={1}",element ,(char)element);
}
if (data2.Length != data.Length)
{
throw new InvalidOperationException("Wrong length!");
}
for (int index = 0; index < data.Length; index++)
{
if (data[index] != data2[index])
{
throw new InvalidOperationException("Data has changed at index " + index);
}
}
string filePath2 = Path.Combine("C:\\check", Path.GetFileName(filePath));
File.WriteAllBytes(filePath2, data2);
data = File.ReadAllBytes(temPath);
data2 = File.ReadAllBytes(filePath);
if (data2.Length != data.Length)
{
throw new InvalidOperationException("Wrong length!");
}
for (int index = 0; index < data.Length; index++)
{
if (data[index] != data2[index])
{
throw new InvalidOperationException("Data has changed at index " + index);
}
}
}
}
}
|
|
|
|
|
SORRY, THE PROBLEM IS ON LINE 61. BEFORE THE PROBLEM WAS ON LINE 41, BUT I ADDED COMMENTS AND SHIFTED THE ENTIRE THING DOWN.
|
|
|
|
|
Hardly surprising - ASCII encoding can only cope with 128 characters. If any of your bytes are greater than or equal to 128, the ASCIIEncoding class[^] will replace them with a question mark. When you re-encode the string, these bytes will have been replaced with the value 63.
You still haven't explained what you're trying to achieve.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am trying to become a good programmer, but following the examples in the books sometimes does not work. The professor in the school is also very suspicious. I think she is reading the chapters before the class and pretending like she knows. She never answers direct questions. The answer always come in the next class session. I feel I am on my own with c#. Sometimes I feel that the people who write the books, don't know any c# at all. How it is possible for examples in text not to work. I encounter this problem many times and it is very frustrating. To add to the frustration, I go online to the help forums and I continually being ask "What are you trying to achieve"? As if a non programmer is not allowed to ask questions and learn from people who know. I am trying to learn from people who know, that is what I am trying to achieve. I hope this answers the question.
|
|
|
|
|
Could you please kindly respond to my new post "Out Of Memory Exception"? It is a completely different question, so I didn't thought it wise to post it here. Thank You.
|
|
|
|
|
computerpublic wrote: I continually being ask "What are you trying to achieve"? As if a non programmer is not allowed to ask questions and learn from people who know.
We don't ask what you're trying to achieve because we don't want you asking questions; it's just that, if you tell us what you want the code to do, we might be able to point you towards a better solution. It's often better to take a step back and look at the bigger picture of what you want to do, rather than fixating on why a particular line of code doesn't do what you expect.
Your professor certainly doesn't sound like she's up to the job. Have you tried talking to your tutor about your concerns?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
<pre>
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Applica
{
class Program
{
static Random _random = new Random (); public static void Shuffle<T>(T[] array)
{
var random = _random;
for (int i = array.Length; i > 1; i--)
{
int j = random.Next(i);
T tmp = array[j];
array[j] = array[i - 1];
array[i - 1] = tmp;
}
} static void Main(string[] args)
{
byte[] outdata = new byte[1];
BitArray[] bits2 = new BitArray[8];
char[] array = {'1','0','1','0','1','0','1','0'};
Shuffle(array);
for (int i = 0; i < 8; i++)
bits2[i] = array[1];
outdata[i] = (byte)bits2;
}
}
}
|
|
|
|
|
|
I would be interested to know exactly what you are trying to achieve with this, particularly as you say it is important to create the decimal array. You read an array of bytes from a file, and copy it to an array of decimals (each element 16 bytes long). You then copy those decimals back to an array of bytes, i.e back to the original, and write them out to a file. So both files contain exactly the same data.
Veni, vidi, abiit domum
|
|
|
|
|
hi!
I am in need of assistance for my project
I need a real example for this.
in the treeview there is the directory and the file that go with it
ex: ----C#
----Test.txt
I have no problem for creating the database in Sql Compact edition
for reading it in the treeview saving it and deleting it
if someone can help with this.
Daniel
|
|
|
|
|
Are you trying to show hierarchical data from your database in a treeview? If so, it would help if you explained the structure of your tables.
/ravi
|
|
|
|
|
 in fact I am trying to build a snippet database for my personnel use
All the one I have seen where a bit complicated to work with
I want to create mine. It will more likely help to understand more the logic behind it
and for the other project that I have with treeview
I am Using SqlCe 3.5 and up.
For the database I have done it this way
static public String Dpath = Application.StartupPath + "\\Data\\";
static public String DB_NAME = Dpath + Application.ProductName + ".sdf";
static public String DB_PWD = "";
static public string sql;
static private string _filename;
static public string filename
{
get { return _filename; }
set { _filename = value; }
}
static private string _filecontent;
static public string filecontent
{
get { return _filecontent; }
set { _filecontent = value; }
}
static public string ConnectString()
{
string connectionString = string.Format("DataSource=\"{0}\"; Password=\"{1}\"", DB_NAME, DB_PWD);
return connectionString;
}
static public void CreateDB()
{
SqlCeEngine en = new SqlCeEngine(ConnectString());
en.CreateDatabase();
en.Dispose();
en = null;
}
static public void CreateTable(string TName)
{
SqlCeConnection cn = new SqlCeConnection(ConnectString());
if (cn.State == ConnectionState.Closed)
{
cn.Open();
}
SqlCeCommand cmd;
sql = "create table " + TName + "("
+ "ID INT IDENTITY (1,1) PRIMARY KEY not null, "
+ "FileName NVarChar(50), "
+ "FileContent NTEXT)";
cmd = new SqlCeCommand(sql, cn);
cmd.ExecuteNonQuery();
cn.Close();
}
If there is a better way of doing it it will be appreciated
Thank'a Lot
Daniel
|
|
|
|
|
If you want to display a TreeView of a directory and its files then why do you need a Database?
Veni, vidi, abiit domum
|
|
|
|
|
Because I know how to do it wit the directory and file but I want to do it with database and that is giving me a headache but still want to make one
tank's
|
|
|
|
|
|
I have some ASP.NET Project Files(.aspx and .aspx.cs)in text format[textfile] in a folder
i wanted to open all project files in My Visual studio how can i open?
NOTE:Not like following process
Select File-->openwith-->Visual studio
When we craeted a website we can see 2 files[Web and Web.Debug] in project folder[physical location] What are these files?
|
|
|
|
|
Sandhya Bandar wrote: I have some ASP.NET Then I think it would be better if you posted your question in the ASP.NET forum[^].
Veni, vidi, abiit domum
|
|
|
|
|
Dear Sir,
I create a C# project "The file version maintain utility"
but I can't understand that how to create this project .
Sir I want to code It's project.
So please sir send me code about 'The file version maintain utility'..
my gmail - mukeshsahani002@gmail.com
your faithful
Mukesh
|
|
|
|
|
It's generally a good idea to start off projects by working out what your requirements actually are. You can break these requirements down into steps that satisfy the needs of each part. From these steps, you should be ready to start coding.
At the moment, it sounds like all you have is a name for the project. Unfortunately, no one is going to write this code for you - we're volunteers only; we don't get paid to write your code.
Final point - it's not a good idea to include your email address in a forum. It will end up attracting spam.
|
|
|
|
|
|
Hi! I have a XNA Project with a XNA-game contained inside a winform.
My program.cs looks like this:
Form1 form = new Form1();
form.Show();
Game1 game = new Game1(form.getDrawSurface());
form.Game = game;
game.Run();
I have a setter and a getter in the winfom like this:
Game1 game = new Game1();
public Game1 Game
{
get
{
return game;
}
set
{
game = value;
}
}
So now I can send values from my form to my Game1 in XNA but not the other way around.
How can I send values from XNA to the WinForm?
I have used som solutions I have found on the internet so I don't fully understand everything.
|
|
|
|
|
Create custom events in your Game1 class and subscribe to those events from the game instance in your form
|
|
|
|
|
Thanks.
Can you give me an example? Is it like a method?
|
|
|
|
|
Form1 form = new Form1();
form.Show();
Game1 game = new Game1(form.getDrawSurface());
form.Game = game;
game.GameEvent += HandleGameEvent;
game.Run();
private void HandleGameEvent(object sender, EventArgs e)
{
}
public class Game1
{
public event EventHandler GameEvent;
protected vitual void OnGameEvent(EventArgs e)
{
EventHandler eh = GameEvent;
if(eh != null)
eh(this, e);
}
}
Check out Basic Event Creation in C#[^] and Events Made Simple[^]
|
|
|
|
|
Thanks, it starting to be clear but it isn´t all that simple to me...
So, suppose something happends in my XNA-game.
There is a update-method were I check if the enemy is alive and within range of Another object:
if (!(enemy.IsAlive && (player.X <= enemy.X + 100) && (player.Y <= enemy.Y + 50 || player.Y >= enemy.Y + 50)))
isActivated = false;
if (enemy.IsAlive && (player.X <= enemy.X + 100) && (player.Y <= enemy.Y + 50 || player.Y >= enemy.Y + 50)) {
if ((depthChargeX >= enemyX - 50 && depthChargeX <= enemyX + 50) || (depthChargeY >= enemyY - 50 && depthChargeY <= enemyY + 50) && isActivated == true)
{
enemy.IsAlive = false;
hit.Play();
wreck2.IsAlive = true;
wreck2.Update(gameTime);
}
}
If it isn´t in range I want to send a bool or something to my form so I can e.g. enable or disable a button.
Would I then send that bool to the OnGameEvent or must I create a new class like in one in one of the examples. I am a little confused still I must admit.
But I suppose the HandleGameEvent in the form listens to the event raised.
And
game.GameEvent += HandleGameEvent;
Is where you subscribe to the event raised by the game.
I also get: The name 'HandleGameEvent' does not exist in the current context but I suppose something is missing.
|
|
|
|