|
What I would do is have the functionality declared in an external assembly - the classes I wanted would implement interfaces stored in a DLL or the Exe and I would then use MEF to wire things together. This would allow you to use the interface as your type in the main program.
|
|
|
|
|
MEF?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
You can actually catch the exception that gets thrown when a class can't be loaded. The trick is that the class must not be used in your Main method, because entering a method which uses a class the point that the class binder tries to load it, and you can't catch it.
So you can do something like
static void Main() {
try { EntryPoint(); }
catch(FileNotFoundException) {
}
}
static void EntryPoint() {
var x = new DependencyClass();
}
The 'correct' way to do it is to handle Application.AssemblyResolve but what I've described here can be useful if all you want to do is tell the user they need to install something which is missing in a more graceful way.
|
|
|
|
|
Thanks BobJanova, this might be all I need.
|
|
|
|
|
how to divided cell in Datagrid view. My code is don't work in fraction number. Someone advise me. Thanks you all.
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
int R1 = row.Index;
for (b = 0; b < dataGridView2.ColumnCount; b++)
{
a = 0;
for (c = 0; c < dataGridView2.RowCount; c++)
{
Ans_Grid.Rows[R1].Cells[b].Value =
(((Double.Parse(dataGridView1.Rows[R1].Cells[c].Value.ToString()))
* (Double.Parse(dataGridView2.Rows[c].Cells[b].Value.ToString())))).ToString()
;
Ans_Grid.Rows[R1].Cells[b].Value = a + Convert.ToInt16(Ans_Grid.Rows[R1].Cells[b].Value);
a = Convert.ToDouble(Ans_Grid.Rows[R1].Cells[b].Value);
|
|
|
|
|
may be decimal will help you in getting your issue fixed
Mouli
|
|
|
|
|
<pre>
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Boolean;
namespace Applica
{
class Program
{
static void Main(string[] args)
{
DirectoryInfo da = new DirectoryInfo("C:\\Folder9");
FileInfo[] Arr = da.GetFiles();
FileInfo ap = Arr[Arr.Length - 1];
long Totbyte = ap.Length;
string filePath = ap.FullName;
string temPath = Path.GetTempFileName();
byte[] data = File.ReadAllBytes(filePath);
File.WriteAllBytes(temPath, data);
byte[] dataB = new byte[1];
BitArray bits = new BitArray(dataB);
for (uint counter = 0; counter < Totbyte; counter++)
{
dataB[0] = data[counter];
for (uint count = 0; count < bits.Length; count++)
{
if (bits[count] == 0)
Console.Write(bits[count] ? "1" : "0");
}
}
}
}
}
|
|
|
|
|
Totbyte is a long. Your loop is a uint.
|
|
|
|
|
Even if I change that variable to a constant, the error still exist.
|
|
|
|
|
My error is in the last 2 lines of the code:
bits[count]
|
|
|
|
|
|
I changed it to an int and I still get an error.
|
|
|
|
|
The same one or a new one?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
He did not insult you, he asked you a perfectly reasonable question. You have stated that you get an error, but you have given no details of what that error is. Is it "invalid argument", and if so on what line of code. If it is something different then show the details. But in either case please be clear what the problem is and where it occurs, and people will try to help you. But if you resort to insults and rudeness you are likely to get no help at all.
|
|
|
|
|
Can you comment all your code?
Then I will fix it for you.
PS: always check variable is null or not, if you are not sure before calling it
|
|
|
|
|
<pre>
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Boolean;
namespace Applica
{
class Program
{
static void Main(string[] args)
{
DirectoryInfo da = new DirectoryInfo("C:\\Folder9");
FileInfo[] Arr = da.GetFiles();
FileInfo ap = Arr[Arr.Length - 1];
long Totbyte = ap.Length;
string filePath = ap.FullName;
string temPath = Path.GetTempFileName();
byte[] data = File.ReadAllBytes(filePath);
File.WriteAllBytes(temPath, data);
byte[] dataB = new byte[1];
BitArray bits = new BitArray(dataB);
for (uint counter = 0; counter < Totbyte; counter++)
{
dataB[0] = data[counter];
for (uint count = 0; count < bits.Length; count++)
{
if (bits[count] == 0)
Console.Write(bits[count] ? "1" : "0");
}
}
}
}
}
|
|
|
|
|
I don't understand what you are trying to do.
But if you want to write out the byte array of the file then here is the code
DirectoryInfo da = new DirectoryInfo("C:\\Folder9");
FileInfo[] Arr = da.GetFiles();
FileInfo ap = Arr[Arr.Length - 1];
long Totbyte = ap.Length;
string filePath = ap.FullName;
byte[] data = File.ReadAllBytes(filePath);
for (int counter = 0; counter < Totbyte; counter++)
{
Console.Write(data[counter]);
}
Remember that is byte array, not bit array
If you to write out bit array instead of byte array, replace
Console.Write(data[counter]);
Into
string yourByteString = Convert.ToString(data[counter], 2).PadLeft(8, '0');
Console.Write(yourByteString+" ");
modified 3-Mar-14 0:40am.
|
|
|
|
|
There are two problems here: firstly that an array index needs to be an integer - and a uint needs an explicit cast to int - you can't use an implicit cast because it could "throw away" data in the form of positive values with the top bit set. Easiest solution: use int value in your for loop.
The second problem is that the BitArray indexer does not return an int value: it returns a bool. So if you correct the first error, the compiler will complain that it cannot compare an int with a bool!
Those are easily fixed to let your program compile:
for (int counter = 0; counter < Totbyte; counter++)
{
dataB[0] = data[counter];
for (int count = 0; count < bits.Length; count++)
{
if (!bits[count])
Console.Write(bits[count] ? "1" : "0");
}
} But... It's not going to work.
You don't change the value in Bits at all inside your outer loop - so each byte "value" is going to print as the same sequence of bits.
Personally, I wouldn't use a BitArray - it's an unnecessary complication here - just use the C# standard bit manipulation operators:
for (int counter = 0; counter < Totbyte; counter++)
{
int b = (int) data[counter];
for (int count = 0; count < 8; count++)
{
Console.Write(b & 1);
b = b >> 1;
}
}
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
I only need to evaluate if whether or not a "0" exist in the BitArray string. I dont care about the "1".
|
|
|
|
|
And what are you going to do if it is a one? now print anything?
Trust me: AND the value with 1 returns either 0 or 1 depending on the state of teh least significant bit the in value. Using >> then shifts the whole input down a single bit, so the second bit takes the place of first, and so forth. It's a lot more efficient than using a BitString for each byte.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
You cannot use an unsigned as an index, it must be signed. And you cannot compare a bit with the integer value zero. A bit can only be true or false . Change the loop code to
for (int count = 0; count < bits.Length; count++)
{
if (bits[count])
Console.Write(bits[count] ? "1" : "0");
}
|
|
|
|
|
I only need to evaluate if whether or not a "0" exist in the BitArray string. I dont care about the "1".
|
|
|
|
|
Then just test for false ; the BitArray[item] is a boolean value.
|
|
|
|