Why is c# and .NET programming considered superior to c++/java/VB?

  • Context: C/C++ 
  • Thread starter Thread starter Gza
  • Start date Start date
  • Tags Tags
    Programming
Click For Summary

Discussion Overview

The discussion centers on the perceived advantages of C# and .NET programming compared to C++, Java, and Visual Basic (VB). Participants explore various features and functionalities of C# that may contribute to its appeal, particularly in the context of transitioning from C++.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant suggests that C# is better than C++ according to their friend, who is successful as an ASP.NET developer, but acknowledges that C++ and C# have different strengths.
  • Another participant highlights features of C# such as lambda expressions, LINQ, and enhanced garbage collection, arguing these contribute to its usability.
  • Participants discuss the syntax differences in property definitions between C# and Java, noting that C# allows for more concise getter and setter definitions.
  • Indexed attributes in C# are mentioned, with an example provided on how they can be used to query a database.
  • The use of foreach loops in C# is presented as a syntactical improvement over traditional for loops in Java.
  • Thread synchronization using the lock statement in C# is noted as a feature that enhances safety in concurrent programming.
  • Delegates and events in C# are discussed, with examples illustrating how they can be used to create extensible classes and handle events.
  • Anonymous delegates are introduced as a feature that allows for more flexible coding without class membership requirements.
  • Partial types, generic collections, and generic delegates are mentioned as additional features that enhance C# programming.

Areas of Agreement / Disagreement

Participants express differing opinions on whether C# is superior to C++ and Java, indicating that no consensus exists on this matter. Some participants appreciate the features of C#, while others maintain that each language has its own strengths.

Contextual Notes

Some participants reference specific features of C# without discussing the limitations or trade-offs associated with these features compared to C++ or Java. The discussion does not resolve the comparative advantages or disadvantages of the languages mentioned.

Who May Find This Useful

This discussion may be useful for individuals considering a transition from C++ to C# or those interested in understanding the features of C# and .NET in comparison to other programming languages.

Gza
Messages
446
Reaction score
0
Hi all, I was wondering whether anyone here had any experience with c# (and .NET programming in general) and why it is so much better than c++/java/VB (this is according to my compsci friend who is making some pretty serious money as an ASP.NET developer) Anyone know some good tutorials for a person transitioning from c++ (5 yrs experience)?
 
Technology news on Phys.org
I wouldn't say it's better than c++ because c++ and c# have different strengths. C# is very much like Java, so it's a tough argument there as well, but personally i prefer C#.
.NET 3.0 adds support for lambda expressions and LINQ which enables you to do SQL like queries on arrays and collections. It also supports DLING and XLing for tying classes with sql and xml schemas.
You also have more control over garbage collection. You can pass parameters by reference (by using ref or out).
In C# you can define attributes, which enable you to hide getters and setters. For example, while in java you might have:
Code:
public class MyCart{
    int unitPrice, numberOfUnits;
    public int GetAmount(){
        return unitPrice * numberOfUnits;
    }
    public int SetAmount(int value){
       unitPrice = (int)(value/numberOfUnits);
    }
}

In c# you can do:
Code:
public class MyCart{
int unitPrice, numberOfUnits;
    public int Amount{
        get{ return unitPrice * numberOfUnits; }
        set{  unitPrice = (int)(value/numberOfUnits); }
    }
}

So you don't have so many visible Getters and Setters, the functionality is the same, but has a natural syntax.

You can also define indexed attributes. For example:
Code:
public class MyObject{
    public object this[string prop] {
        get{
            //for example we can query a database to get the property
            SqlConnection conn = new SqlConnection(...);
            SqlCommand comm = new Command("SELECT " + prop + " from MyTable WHERE filter = value", conn);
            object o = comm.ExecuteScalar();
            conn.Close();
            return o;
        }
    } 
}
//usage
MyObject o = new MyObject();
Response.Write(o["FirstName"]);

You have foreach/in loops, which enable you to replace:
Code:
String[] ss = new String[]{ "a", "b", "c" };
for(int i=0; i<ss.length(); i++){
     doSomething(ss[i]);
}

With:
Code:
string[] ss = new string[]{ "a", "b", "c" };
foreach(string s in ss){
    doSomething(s);
}

Goto is supported.
You can also use lock() for thread synchronization, i.e.:
Code:
public static object MySharedVariable = new object();
public void DoWork(){
    lock(MySharedVariable){
       //read or write shared variable safely   
    }
}

Then you have delegates and events. You can use += and -= to register and unregister event handlers. With delegates you can write extensible classes. For example, you do a custom search control which does automatic paging of the results, but you want to let the programmer build the database search query according to his needs. You can define a delegate:
Code:
public delegate string[] DoSearch(string[] terms);
public DoSearch Search;

And your class will call Search() to obtain the search results. So the prgrammer can use your control in the following manner:
Code:
public MyClass{
    SearchControl sc = new SearchControl();
    sc.Search = new DoSearch(this.MySearch);
    myWindow.Controls.Add(sc);
}
public string[] MySearch(string[] terms){
    //search here
    return results;
}

Anonymous delegates are only different in that they don't need to be members of a class i.e.:
Code:
SomeDelegate del = delegate                         
                         {
                             MessageBox.Show("Hello");
                         };
del();

There are also partial types, generic collections (as in Java) and generic delegates. A bunch of stuff really.
 
Last edited:
This was an excellent intro, thank you very much. Any good books/resources you recommend?
 
I use the following site as a C# reference:
http://www.softsteel.co.uk/tutorials/cSharp/lesson1.html

It's the first one i found back when i was learning C#, there might be some other ones. You might also search MSDN for any articles on moving from C++/Java to C#.
 
Last edited by a moderator:
try this tutorial

http://chsarp.net-informations.com

thank
chan.
 
Last edited by a moderator:

Similar threads

Replies
3
Views
4K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 31 ·
2
Replies
31
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 15 ·
Replies
15
Views
5K
  • · Replies 13 ·
Replies
13
Views
6K
  • · Replies 10 ·
Replies
10
Views
3K
Replies
7
Views
22K