|
Since the link was already on the survey...
Good point but this is C# related and that's why I didn't mark it as a question.
|
|
|
|
|
Hi all,
y = 2;
string yString = y;
This of course does not work ,Cannot implicitly convert type 'int' to 'string'.
But this is no problem:
y = 2;
string yString = "" + y;
Why??
Regards,
Grooover
0200 A9 23
0202 8D 01 80
0205 00
|
|
|
|
|
Because the designers of .NET C# decided that the "+" operator between strings ... if the item before the plus-sign is a string ... would automatically invoke conversion of all items to the right of the plus-sign to Type String.
You can see an even more dramatic example of this if you execute:
int v = 1;
Int32 w = 2;
Int64 x = 3;
double y = 4;
float z1 = 5;
Single z2 = 6;
string yString = "" + v + w + x + y + z1 + z2; Yep, it compiles. So, you can infer that ... given a lack of parentheses) arithmetical operator evaluation for the plus sign is "turned off."
If you think this is kind of strange, you may not be alone
“I speak in a poem of the ancient food of heroes: humiliation, unhappiness, discord. Those things are given to us to transform, so that we may make from the miserable circumstances of our lives things that are eternal, or aspire to be so.” Jorge Luis Borges
|
|
|
|
|
Thank You for your explanation,
Learn something every day.
thanks
0200 A9 23
0202 8D 01 80
0205 00
|
|
|
|
|
Thing of beauty, .NET.
Regards,
Rob Philpott.
|
|
|
|
|
The concatenation operators are replaced by calls to one of the overloaded string.Concat methods. There are versions with string or object parameters, e.g Concat(string, string, string), Concat(object, object, object), and if possible the more efficient (string, string, ...) versions will be used.
This gives us, well me really, the opportunity to play with ILDASM and have a look at what the C# compiler decides to do.
private static String StringConcat(String a, String b, String c) {
return a + b + c;
}
private static String ObjectConcat(String a, int b, DateTime c) {
return a + b + c;
}
and the IL shows the use of the different Concat methods.
.method private hidebysig static string StringConcat(string a,
string b,
string c) cil managed
{
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: ldarg.2
IL_0003: call string [mscorlib]System.String::Concat(string,
string,
string)
IL_0008: ret
}
.method private hidebysig static string ObjectConcat(string a,
int32 b,
valuetype [mscorlib]System.DateTime c) cil managed
{
.maxstack 8
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: box [mscorlib]System.Int32
IL_0007: ldarg.2
IL_0008: box [mscorlib]System.DateTime
IL_000d: call string [mscorlib]System.String::Concat(object,
object,
object)
IL_0012: ret
}
Alan.
|
|
|
|
|
Hi all.
I need to write to a file --file names-- while looping a folder. So i did this:
string foldername = this.srcfbdlg.SelectedPath;
StreamWriter sw = new StreamWriter("data.txt", true);
var txtFiles = Directory.EnumerateFiles(foldername, "setup.exe", SearchOption.AllDirectories);
foreach (string currentFile in txtFiles)
{
string fileName = currentFile.Substring(foldername.Length + 1);
File.AppendAllText("data.txt", fileName);
}
The problem is, while looping, AppendAllText() gives me the error "File cannot be accessed. I think that's because while looping the writing process overlaps, hence the bug. Is there a way around, without like making a timer to write or something?
Thanks for any reply guys.
|
|
|
|
|
OK...you can't see the problem yourself?
You have two different methods of adding data ready and in use in that code:
StreamWriter sw = new StreamWriter("data.txt", true); Sets up sw to append to the file data.txt - which means opening the file and acquiring an exclusive lock so the file content can;t be changed while you are writing to it.
Then:
File.AppendAllText("data.txt", fileName); Which tries to open the file data.txt for append by acquiring an exclusive lock so the file content can;t be changed while you are writing to it.
And fails, because there already is an exclusive lock open on the file...by your code.
So, either use the sw stream to write to the file, or get rid of it completely, and just use the File.AppendAllText method instead - but don't try to use both.
And if you do go with your own stream (which in this case is probably a good idea as you only open and lock the file once) remember to Close and Dispose the stream when you have finished - or the next time you call that code the file will still be locked from the first time!
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 – ∞)
|
|
|
|
|
Hey thanks man learned some stuff from that. And it worked :v
Later
|
|
|
|
|
You're welcome!
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 – ∞)
|
|
|
|
|
Hi..!
i want to make an application in C #
that will standardized .ppt and .pptx files.
now i want to extract the text in files
and check following properties.
font style, font size,heading and sub heading style and size, number of bullets in each slide etc..
Can anyone help to do the following things in C Sharp..
please share your ideas and experience related to this with me.
All of you are warmly welcome..
Thankssss in advance....
|
|
|
|
|
|
thanks but how can i change the font size and style in a ppt file through C#.
|
|
|
|
|
taimurhasan wrote: how can i change the font size and style in a ppt file through C#. You will have to find the appropriate calls in the interop as documented in the link I gave you.
|
|
|
|
|
|
If you know how to do it within Powerpoint, record your actions as a macro, then look at the generated code - this will give you big hints about what you need to do in C#, even though the code will be in VBA
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Sorry i can't understand what you want to say.. can u explain ??
|
|
|
|
|
Hi I'm brand new to this stuff and still grasping the concepts and terms associated with C#
I was looking through my C# book and came across this example project. It asked you to create a one-form application that will gather the following:
First Name
Last Name
Address
City
State
Zip
Telephone
You must include the following features:
The form must start in the center of the screen.
You must have a nice title for your form.
There must be an END button that stops your program.
You need another button that will display a message box when they click it. The message needs to say "Thanks for shopping [Name]".
All the fonts/colors/alignments must look clean and orderly.
I know to an experienced C# programmer, this kind of stuff is second nature. I'm looking for anyone who could help me out with any infomation so I can understand this a little more (since the book didn't show how to do it!) Thanks!
|
|
|
|
|
|
Member 10784174 wrote: the book didn't show how to do it!
Your book probably does show how to do it, but it won't spell it out for you - part of learning development is learning to think about the problem and work out a solution - it expects you to apply what it has told you, not blindly regurgitate it (unlike most school work).
If you can't work out what it means in one go, then do each bit separately: first, center the form. Then change the title. And so forth. Doing it that way, it's a very simple task, honest!
If you don't think the book has explained what you need to do, then there are two possibilities:
1) It's a rubbish book. Check the title: does it have "for Dummies", multiple exclamation marks, or "in xxx days" in it? If it does, then it's almost certainly rubbish. If it doesn't, it's probably ok.
2) You aren't reading the book, just skipping through and trying one of the exercises without trying to understand the material in the chapter(s) before it.
The solution to the first is simple: get a better book. Anything by Addison-Wesley, or Wrox is probably fine.
But I suspect you need the second solution: Go back to page one, and start reading from there. And do the exercises in order as you meet them!
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 – ∞)
|
|
|
|
|
Interesting book that only asks you to do stuff without explaining it first. What is the title?
Regards,
Rob Philpott.
|
|
|
|
|
I bet it's something like Learn C# in 24 Hours.
|
|
|
|
|
Rob Philpott wrote: What is the title
It's titled, "Go to CodeProject and get the people there to do your homework for you".
|
|
|
|
|
Yes, that was my suspicion as well..
Regards,
Rob Philpott.
|
|
|
|
|
Hi I'm brand new to this stuff and still grasping the concepts and terms associated with C#
I was looking through my C# book and came across this example project. It asked you to create a one-form application that will gather the following:
First Name
Last Name
Address
City
State
Zip
Telephone
You must include the following features:
The form must start in the center of the screen.
You must have a nice title for your form.
There must be an END button that stops your program.
You need another button that will display a message box when they click it. The message needs to say "Thanks for shopping [Name]".
All the fonts/colors/alignments must look clean and orderly.
I know to an experienced C# programmer, this kind of stuff is second nature. I'm looking for anyone who could help me out with any infomation so I can understand this a little more (since the book didn't show how to do it!) Thanks!
|
|
|
|
|