|
To read the number of bytes, you can use Systm.Text.Encoding.Default.GetByteCount .
The most accurate way to count lines would probably be to use StringReader.ReadLine , but if that's too much overhead, try this function:
static int LineCount(string str)
{
int lines = 1;
for(int i = 0; i < str.Length; i++)
{
if(str[i] == '\r' || str[i] == '\n')
{
if(i+1 < str.Length && (str[i] == '\r' && str[i+1] == '\n'))
i++;
lines++;
}
}
return lines;
}
-- modified at 19:13 Monday 29th August, 2005
|
|
|
|
|
hi,
how can i read information from a excel table...for example i want to read the row A1 and to write another value back....
any idea to do that?
bye
|
|
|
|
|
|
hi, i compiled this sample!
and i got that error:
private Excel.Application ExcelObj = null;
error CS0246: The type or namespace name 'Excel' could not be found (are you missing a using directive or an assembly reference?)
but the Interop.Excel Assembly = icrosoft Excel 11.0 Object Library is in the projekt!! hmmm...
cu
|
|
|
|
|
I've made a little application for opening pictures using pictureboxes. I've used File Type Editor to connect my app with .bmp. .jpg, . gif etc. file types. After instalation, when I doubleclick a picture file, my app runs, but there is no picture in pictureBox1. I know I have to do something with Arguments property, but I dont know what. I've tried:
public static void Main(string[] args)
{
Application.Run(new Form1());
args=Environment.GetCommandLineArgs();
foreach (string arg in args)
{
fajl=fajl+arg;
}
pictureBox1.Image=Image.FromFile(fajl);
}
How to make doubleclicked file apear in pictureBox1??
please help!
|
|
|
|
|
The line after Application.Run(new Form1()); will not be executed untill you close the form.You should put your code either in Form1 constructor or in form_load event handler or in form_activate event handler
for example:
public static void Main(string[] args)
{
Application.Run(new Form1(args));
}
private Form1(string[] args)
{
foreach(string arg in args)
fajl+=arg;
pictureBox1.Image=Image.FromFile(fajl);
}
P.S. remember that Form1 constructor is an instance member (not a classifier) then none of the variables within it can be static or you should use Form1.variableName to refer to them.
|
|
|
|
|
Thank you, thank you, thank you
It works perfectly now ;);)
|
|
|
|
|
I have an Visual C#.NET 2003 and want to develop a "Smart Device Application", but it isn't contained in the New Project dialog.
I've also installed:
.NET Compact Framework
Microsoft Pocket PC 2003 SDK
Mobile Application Development Toolkit
But I'm still not able to create that mysterious "Smart Device Application"
If I have some TOO CHEAP edition of VS IDE, is there some alternative IDEs which support mobile development?
|
|
|
|
|
Hi,
I would like to have a Web Update feature to enable a desktop app to update over the web.
Does anyone have any ideas/samples on how to do this?
I would like to check and download only the files that have changed.
Thanks in advance
Stephen McAllister
|
|
|
|
|
Hi Buddy,
I am also looking same kind of thing please if you found any hel regarding this please inform me.
Muhamad Waqas Butt
waqasb4all@yahoo.com
-- modified at 10:41 Saturday 27th August, 2005
|
|
|
|
|
|
does anybody know how to find all reference types of given object and set them all to null state, so given object can be available for GC?
for example..
object _a = new object();
object _b = _a;
now we have two reference type objects which are pointing to the same memory block.
the thing is that I don't know anything about "_a" and would like to set it to null state somehow from "_b".
what do you think?
luke
|
|
|
|
|
|
hi leppie,
thank you fast reply.
how would you set NULL state for those 2 references if you know only one of them?
luke
|
|
|
|
|
You can't. There is no backward reference from the object to it's references.
This sounds like the all too common situation where someone tries to fix bad programming with some magic command. You just have to keep track of your references.
---
b { font-weight: normal; }
|
|
|
|
|
thanks. ok, i'll just keep the track
|
|
|
|
|
This sounds like the all too common situation where someone tries to fix bad programming with some magic command. You just have to keep track of your references.
I was thinking that this sounds like the all too common situation where someone tries to fix bad programming with even worse programming.
Why in the heck would you want to null out references about which you know nothing? Just for the pleasure of seeing those lovely unhandled NullReferenceExceptions ? (Okay, I suppose that would provide a first step in tracking down those references that you couldn't find, but the OP didn't say that was the goal (if it was, mock objects would probably be a better solution anyhow)).
Matt Gerrans
|
|
|
|
|
I have noticed that I need not put any DLLImport statements in Windows application if I am using some DLLs. I just need to add those DLLs in the reference and then use it.
My question is when is it necessary to have a DLLImport statement in my C# code?
Thanks and Regards,
Amit
|
|
|
|
|
The DllImport are required when you want to call into pre-.NET DLL, i.e. C dll.
If it's a .NET dll (i.e. an assembly) no problem, if it's a C DLL, you need to do interop.
Interop is a vast topic but well documented in the SDK's documentation, I suggest you to refer to it.
Basically C# need to know about the function to use it, right?
C DLL define no metadata that could be used by other .NET dlls to knwo about its content (they just define C header usable by a C compiler), therefore you have to do these declaration yourself.
That's the purpose of DllImpoert.
You've got most of win32 API Interop declaration there:
http://pinvoke.net/[^]
|
|
|
|
|
Thanks for the answer. It, indeed, answers most of my initial questions. Now, I am trying to write a wrapper for LAPACK [http://www.netlib.org/clapack/faq.html], which is available in C and FORTRAN in C#. It is a highly optimized linear algebra subroutines. Do you have any idea about a place where I can go to learn the secret of the "writing wrappers in C#" business.
Thanks and Regards,
Amit
-- modified at 20:24 Friday 26th August, 2005
|
|
|
|
|
You should really learn to use the documentation coming with the SDK.
In the "index" side panel there is a box named "look for", just type: "interop", "COM interop" or "data marshaling" in it and you will find a wealth of information.
Alternatively, if you've got issue with the SDK documentation (strangely many .NET developer seems to ignore about its existence) you could go on MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconinteroperatingwithunmanagedcode.asp[^]
Anyway about array marshaling (let's say float[]) the documentation doesn't straightforwardly explained you wether or not the whole array is copied or not to a temporary buffer every crossing the managed/unmanaged boudary (I think some attributes control that behavior).
But always have the solution to use unsafe code & float* in C# or, as I prefer to write my wrappers now, use ManagedC++ (v2.0, meach cleaner, leaner and less ambiguous).
|
|
|
|
|
I have come across this wrapper word many times. Many people have written wrappers for C# for subrountines which are not written in C#. My question is what this wrapper is and how it can be used as to include other sub-routines in a C# application?.
Regards and Thanks,
Amit
|
|
|
|
|
Basically in C# you can call directly into C function that's "easy" thanks to interop!
But you still have to declare the C function in C#, with correct data structure, sometimes it's not so trivial toredefine in .NET the C data structure. You might also have many function to re-declare, quite tedious, particularly if there is, let's say, hundreds of them!. And you might as well simplify the C# API compare to the C API.
It's what a wrapper is for.
|
|
|
|
|
How do I pass a two doubles as a PointF args?
I converted them from a TextBox using Convert.ToDouble...
If I can't do it, any way around it?
thanks in advance....
|
|
|
|
|
is it a joke? what are you trying to do?
just in case you ask for the obvious and missed it, let me state it:
PointF ToPointF(double x, double y)
{
return new PointF((float) x, (float) y);
}
if it is what you were looking for and didn't find it I suggest you read: "Learning C#" by Someone...
|
|
|
|