|
C# vs VB is all a matter of style.
If you look closely at the features of both languages, you'll see that VB offers about as many features that C# doesn't have that C# offers that VB doesn't have.
C#:
- allows unsafe code (I've yet to meet anyone who does this in C# though)
- has the 'as' operator (but VB has it in 2005 - 'TryCast')
- allows assignments within expressions (e.g., if ((x = y.Value) == 2))
- operator overloading
VB:
- has optional parameters
- allows types within interfaces (although I've never wished I had this in C#)
- has a very flexible Select construct (much, much more flexible than 'switch')
- has the "When" filter for catch block headers (ok - I'm really stretching now...)
And this one is a doubtful benefit of VB: it gives you half a dozen ways to do a lot of things - some regard it as a benefit, while others hate it since it makes it harder to produce standard code in teams.
David Anton
Tangible Software Solutions
www.tangiblesoftwaresolutions.com
Home of:
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter
|
|
|
|
|
Hi David. Have I bought your program ? Whichever VB->C# converter I bought, it truly rocked !!!
David Anton wrote:
allows unsafe code (I've yet to meet anyone who does this in C# though)
You're talking to one right now. Vital for image processing, although I'm told there's a non-unsafe way, I am yet to see the code to know what it is ( setpixel does NOT count ).
David Anton wrote:
has the 'as' operator (but VB has it in 2005 - 'TryCast')
Trouble is, most VB.NET users prefer to use the older casting operators, the ones that were in VB6. The problem with VB.NET is not lack of features, it's terrible hacks that have been maintained for legacy support ( and which Microsoft initally wanted to remove ).
David Anton wrote:
VB.NET : has optional parameters
Yeah, these would be nice, although I read a rationale against them online which made sense. All about performance.
David Anton wrote:
And this one is a doubtful benefit of VB: it gives you half a dozen ways to do a lot of things - some regard it as a benefit, while others hate it since it makes it harder to produce standard code in teams.
A problem that VB.NET only intensifies. It's my experience, from working on projects that are already in progress, that on average, VB.NET users know a hell of a lot less about good design and coding standards than C# users. It's also my experience that they don't use the new VB.NET features, because they are coding as if it was still VB6. I doubt many of them even know what it is they are asking the compiler to do.
Whichever converter I bought, it won me a whole lot of work, because I was able to convert a huge VB.NET program to C#, and I have worked on it ever since. I agree, style is an issue, I hate VB.NET syntax, but there's more to it than that, and the core issue is the sort of people who are using each language, on average. I'm sure there are good VB.NET coders and bad C# coders in the world, but overall, the trend is in the other direction.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I have been working with xml files for a while; however, now I have to work with a xml file that has several relations that are not hierarchical which makes it a bit harder to manipulate with XmlDocument so I figured I could use datasets because a dataset automatically creates all the necessary tables. So to test it out I assign a table to the datasource of a datagrid.
My problem is that when new rows are added to the datagrid, and I call my dataset's WriteXml method, the new rows are added at the root level and my file looses its original tree hierarchy.
For example, if my original xml file is as follows:
<?xml version="1.0" standalone="yes"?>
<root xmlns="http://tempuri.org/Database.xsd">
<Database>
<Positions>
<Position PositionCode="1" PositionName="Operations Supervisor" Salary="0" />
</Positions>
</Database>
</root>
Then I set the DataSource to of a datagrid to "Position" table and after adding a couple of rows, the saved file looks like:
<?xml version="1.0" standalone="yes"?>
<root xmlns="http://tempuri.org/Database.xsd">
<Database>
<Positions>
<Position PositionCode="1" PositionName="Operations Supervisor" Salary="0" />
</Positions>
</Database>
<Position PositionCode="2" PositionName="Secretary" Salary="0"/>
<Position PositionCode="3" PositionName="LazyGuy" Salary="0"/>
</root>
Note that the new rows were added in "/root" instead of in "root/Database/positions"
Please let me know if there is a way to preserve the xml tree hierarchy when using datasets.
Many thanks in advance.
|
|
|
|
|
Hello,
i'm sending a message from a C++ program to a C# program using following code:
CString strParam = "TEST";
pWnd->SendMessage (WM_USER + 200, NULL, (LPARAM)(LPCSTR)strParam);
In C# i have following code:
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_USER + 200)
{
string strTest = (string) m.GetLParam (typeof(string));
}
base.WndProc (ref m);
}
I want to get the string in the C# program using the m.GetLParam method. However, that does not work. Do you have any ideas?
|
|
|
|
|
I don't know if it's the case here (it's been years since I programmed in Win32) but some messages parameters are not marshalled across process boundaries.
When you use WM_GETTEXT to get another process's window caption, Windows sees that you are passing a pointer, and copies the memory pointed to by the address in lParam to the other process, sends the message, and then brings the memory back to your process.
But if it's a app-specific message (above WM_USER ) Windows has no way of knowing that the lParam is a pointer to some memory located somewhere else in your process address space, instead of a scalar value.
In this case, you would need to use ReadProcessMemory /WriteProcessMemory (are they called like that?).
You could also try the WM_COPYDATA message. As far as I understand, this message was designed specifically for this kind of uses (interprocess communication) and the data gets marshalled automatically.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
hii all,
what is the Cache-Control and what is the diffrence between private and public cache?
thanks alot for your time.
marcoryos
|
|
|
|
|
Is a static object unique the the application compartment it is contained in? Or if you have 2 identical applications running, will they share the same static object?
I'm guessing it's independant. But i just need to check.
Cheers
Cata
|
|
|
|
|
|
Hi @all,
I have a ListView and a VScrollBar (I need the Scroll event...) on it with ListView.Scrollable set to false, because the ListView's ScrollBar would be on top always, so that I could not access my VScrollBar. But my problem is: How can I access the ListViewItems that are not visible? I tried to call the EnsureVisible() method at the Scroll event . The result was: The VScrollBar scrolled but the ListViewItems that are not visble didn't scrolled into view. It seems to be that the EnsureVisible() method only take effect if ListView.Scrollable is set to true. It must be a simple work - it drives me crazy! Please help!
|
|
|
|
|
If you make your control not scrollable, it won't scroll. I doubt there is a simple way around this, it's doing what you asked it to.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
It could be possible to modify control styles to get rid of the scroll bar - must be done through interop though (calling into Win32 API) and still have control thinking it is there (by setting scrollbar's visible to false or similar). I don't think it is too easy as I had a lot of hard time fidling around ListView - it has a lot of strange behaviours under .NET (did you know it is owner-drawn under .NET at all times?)
Regards
JP
|
|
|
|
|
[DllImport("user32.dll")]
static extern bool ShowScrollBar(IntPtr hWnd, int wBar, bool bShow);
the call...
ShowScrollBar(listView1.Handle, 1, false);
...works!
Sebastian.
|
|
|
|
|
Has anyone created a method to self-destruct a program yet? Screw all the timed licenses and date-diffs, I want my program to just disapear at xxx time and not be recoverable. end of story! done deal!!!
any ideas?
any takers?
Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."
Why is common sense such an un-common comodity?
|
|
|
|
|
Yeah, that's easy. You need a second program whose sole job is to delete the first. Then put it in the runonce section of the registry, and it will be deleted the next time the user starts their machine.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
Does anybody know if there is a SNMP simulator in C# out there?
Any help would be appreciated!
Thanks!
|
|
|
|
|
|
I have serialized my bussiness objects to a file and tried to deserialize them
but it took so much time that creating those objects and putting data into them from database is even faster.
Am I missing any thing?I have though that the deserialization process for my objects from a file should be much much faster as I do not have to create the objects?
MY CODE
***********************
public static void SerializeIdentityMapRegistry()
{
System.IO.Stream s = System.IO.File.OpenWrite(@"C:\Documents and Settings\dogat.ILKON\Desktop\imap.dat");
BinaryFormatter b = new BinaryFormatter();
b.Serialize(s, DAL.identityMap.IdentityMapRegistry.getInstance());
s.Close();
}
public static void DeserializeIdentityMapRegistry()
{
System.IO.Stream s = System.IO.File.OpenRead(@"C:\Documents and Settings\dogat.ILKON\Desktop\imap.dat");
BinaryFormatter b = new BinaryFormatter();
DAL.identityMap.IdentityMapRegistry.Instance = (DAL.identityMap.IdentityMapRegistry)b.Deserialize(s);
s.Close();
}
|
|
|
|
|
First of all:
No .Net serialization isn't very fast. Almost ever you will be by far faster if you (as an example) write a binary file yourself. But this surely means you have to do the major work yourself.
To your problem:
Check your DAL.identityMap.IdentityMapRegistry for unneeded references. Keep in mind that every reference this class holds gets also serialized (and those who are referenced by those which are referenced...). It's a very common mistake that just too much gets serialized - so check it carefully.
|
|
|
|
|
|
I'm using the articl of Twain published on the codeproject, but i have alittle problem which is:
the reutrn datatype is IntPtr, which i can't convert to a bitmap.
what can i do?
|
|
|
|
|
Is the IntPtr a GDI bitmap handle? If yes, look at the System.Drawing.Bitmap.FromHbitmap static method.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
I'm trying to use a combo box on a windows form which will change its display on event of changing combo selection. This is the method I wrote:
private void SurveyChooserCombo_SelectedIndexChanged(object sender, EventArgs e)
{
DAL dal = new DAL();
switch (SurveyChooserCombo.SelectedIndex)
{
case 0:
SrNo = 1;
break;
case 1:
SrNo = 2;
break;
case 2:
SrNo = 3;
break;
default:
SrNo = 3;
break;
}
It doesn't do the job.
Please help me find why.
TIA,
sea#
|
|
|
|
|
|
"doesn't do the job" is very vague, what doesn't work in particular?
modified 12-Sep-18 21:01pm.
|
|
|
|