|
To add to what the others have said: get rid of the semicolon.
foreach (blah blah in blahs);
if (myCondition) Becomes
foreach (blah blah in blahs)
if (myCondition)
With it present, the if condition is executed outside the loop, not in as the indentation suggests.
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
I am not sure, but I think you can do:
foreach (blah blah in blahs)
if (myCondition)
blah.Name = "Hello";
|
|
|
|
|
This should get you along the way.
foreach (String filename in dir.GetFiles("*.html")){
FileInfo finfo = new FileInfo(filename);
if (Application.Current.Properties["finfo"] != null){
}
}
hope this helps.
|
|
|
|
|
Sorry for the late reply, Thank you V this worked perfectly.
|
|
|
|
|
Cool, glad to be of help
|
|
|
|
|
I am trying to create a file on a directory where I have total power.
The File.Create (..) (as well as any other attempt to create the file even using FileStream()) always fails with the UnauthorizedException .
This is not possible since I have permission to write and create files on that directory (after all I can easily create a file by hand there).
Is there an explaination ?
|
|
|
|
|
tiwal wrote: This is not possible since I have permission to write and create files on that directory (after all I can easily create a file by hand there).
Lousy way to test.
Does your code run under YOUR credentials? What path and filename are you trying to write to?
|
|
|
|
|
I am running a debug instance of my program.
VS runs under my credentials.
The path is simply the debug folder of the application.
This is the same path where I was successfully reading and writing, yesterday, using the same VS, and NO change has been made since .
|
|
|
|
|
tiwal wrote: This is the same path where I was successfully reading and writing, yesterday, using the same VS, and NO change has been made since
If the universe did not change it would behave the same. Something changed.
Are you running a copy off the application outside the debugger? Viewing the file using a viewer that could "lock" the file?
tiwal wrote: VS runs under my credentials.
There's no "run as admin"-shield on the taskbar-icon?
|
|
|
|
|
Something has changed for sure . But if I were the one who changed that something I wouldn't be here to pose this question.
I am not running anything which may lock the file. After all the file cannot even be created.
Running the environment as administrator even worsened things, as now the path of the file changed to something "like" root ("C:.\filename", which doen not even elaborate to a regular path).
|
|
|
|
|
tiwal wrote: as now the path of the file changed to something "like" root ("C:.\filename", which doen not even elaborate to a regular path). I would suggest you have a bug in your code which is leading to an invalid path somewhere. Use your debugger to step throught the code and see the exact values of the variables that are used to create the path.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Depends on what user the application is running under, rather than what access you have.
If this is winforms, then I would expect it to run under your user, but a service won't, for example.
Double check the folder address, and check the user ID it runs under - if it is complaining, then it is doing so for a reason!
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
I am not sure I am understanding well. Tou mean , checking the folder I am trying to write to ?
|
|
|
|
|
Check the name, yes - make sure that the folder you are trying to write to is exactly the folder you think it is.
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
hellow every body
I know this question is verey primary but I realy need its answer
how can i use poinrets in C#? please help me by an instance
|
|
|
|
|
You would also have to explain "what" the problem might be. If the problem is as broad as "I don't understand them", then the answer will be equally broad. For a general introduction to the topic, see MSDN[^].
|
|
|
|
|
tnx u
|
|
|
|
|
|
In order to use true pointers, you need to execute what is called unsafe code
This means you have to do two things:
1) Turn on unsafe code in your app (it is off by default). This is on the Build tab of your project properties.
2) Put the pointer use into an unsafe block. There is an example on the MSDN page: http://msdn.microsoft.com/en-us/library/chfa2zb8(v=vs.71).aspx[^]
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
It depends on what you need them for...
As others have said, you can use unsafe code. Alternatively, you can often use SafeHandle s, GCHandle s, GC.AllocHGlobal / GCFreeHGlobal along with IntPtr etc instead to achieve most things without needing to go quite as far as unsafe.
Without knowing the specifics then it is impossible to advise what is the best solution.
|
|
|
|
|
I doubt that your real need it to use pointers. Your need is to solve a problem that requires you to use pointers in languages like C and Pascal. That doesn't mean you need to use pointers in other languages.
In C#, every object is implicitly referenced through a "pointer" (which isn't a memory address, but an object reference). Say, to build a directed tree in a brother/son fashion, you declare your "myObject" class defines members "brother" and "son", both of class "myObj". Their values are not stored in the current node; the current node refers to ("has pointers to") the brother and son. There is no syntactical indication of this, because it is always so for class members.
Atomic members such as int and bool do reside in the class object, object members never do. You must be aware of this distinction - e.g. if you use the int member "age" as a method argument (without modifiers), a copy is provided to the method, but if you use "brother" as an argument, a reference ("pointer") is provided, not an object copy.
If you do not want to sent a copy of a single int, but a reference, you can use the Int class, which behaves just like your myObject instances: A reference is passed, not a copy of the value. But note that you don't need to use Int objects for allowing a method to change a parameter; you can add the modifier "ref" (or "out") to it, but you must add "ref"/"out" both in the formal declaration of the method and everywhere it is invoked.
The only time you need to handle pointers in C# is when interacting with unmanaged code, e.g. for a number of Windows system calls that are not directly available in C#. But you should avoid "using" pointers as much as possible: Treat them as opaque handles. Above all: Stay completely away from doing arithmetics on pointers! (Those who know what can and can't be done in that area need not ask questions about pointers in C#... )
|
|
|
|
|
Why isn't the following changing the value of the label LanguageSpoken?
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
LanguageSpoken.Text = cboUserLanguage.SelectedText;
}
private void Form1_Load(object sender, EventArgs e)
{
cboUserLanguage.SelectedIndex = 0;
LanguageSpoken.Text = cboUserLanguage.SelectedText;
}
Jon
|
|
|
|
|
cboUserLanguage.SelectedIndex = 0; Put a breakpoint on that line, and see what the SelectedIndex is before the assignment. If it is already 0 (could be set in the designer), then there will not be a "change".
|
|
|
|
|
Look here. Seems that there are problems when using it in click handler.
I suggest using cboUserLanguage.Items[cboUserLanguage.SelectedIndex].ToString(); instead.
|
|
|
|
|
suppose i have two image with same height and width. pic1.jpg & pic2.jpg. two image look pretty same with minimum difference. with the help of below routine we can get the difference between two images.this below routine is not my routine.
public class ImageDifferences
{
private static ILog mLog = LogManager.GetLogger("ImageDifferences");
public static unsafe Bitmap PixelDiff(Image a, Image b)
{
if (!a.Size.Equals(b.Size)) return null;
if (!(a is Bitmap) || !(b is Bitmap)) return null;
return PixelDiff(a as Bitmap, b as Bitmap);
}
public static unsafe Bitmap PixelDiff(Bitmap a, Bitmap b)
{
Bitmap output = new Bitmap(
Math.Max(a.Width, b.Width),
Math.Max(a.Height, b.Height),
PixelFormat.Format32bppArgb);
Rectangle recta = new Rectangle(Point.Empty, a.Size);
Rectangle rectb = new Rectangle(Point.Empty, b.Size);
Rectangle rectOutput = new Rectangle(Point.Empty, output.Size);
BitmapData aData = a.LockBits(recta, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
BitmapData bData = b.LockBits(rectb, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
BitmapData outputData = output.LockBits(rectOutput, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
try
{
byte* aPtr = (byte*)aData.Scan0;
byte* bPtr = (byte*)bData.Scan0;
byte* outputPtr = (byte*)outputData.Scan0;
int len = aData.Stride * aData.Height;
for (int i = 0; i < len; i++)
{
// For alpha use the average of both images (otherwise pixels with the same alpha won't be visible)
if ((i + 1) % 4 == 0)
*outputPtr = (byte)((*aPtr + *bPtr) / 2);
else
*outputPtr = (byte)~(*aPtr ^ *bPtr);
outputPtr++;
aPtr++;
bPtr++;
}
return output;
}
catch (Exception ex)
{
return null;
}
finally
{
a.UnlockBits(aData);
b.UnlockBits(bData);
output.UnlockBits(outputData);
}
}
}
}
after getting the difference how could i merge the difference on first image.
this below way we can merge
using (Graphics grfx = Graphics.FromImage(image))
{
grfx.DrawImage(newImage, x, y)
}
but we need to know the x & y from where the new image will be drawn on first image. can any one tell me how can i get the x & y position from the above routine called PixelDiff() thanks in advance.
tbhattacharjee
|
|
|
|