What i would like in C# (5.0)

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »

46 Replies - 9762 Views - Last Post: 22 June 2011 - 11:12 PM

#1 marinus   User is offline

  • D.I.C Addict
  • member icon

Reputation: 138
  • View blog
  • Posts: 575
  • Joined: 14-April 10

What i would like in C# (5.0)

Posted 30 March 2011 - 02:04 AM

Hi CSharpers

I am busy on a project which will have lots of private integer values , now i see that i would have to declare private every where , which is not the case in C++.

In C++ you can declare all you're private methods\variables in a very nice fashion. e.g

C++

class SizeCalculater {

   private :

       /*Here you put all you private
       members in this part without having to 
       declare private over and over again*/

	const int _2Seater = 1;
	const int _3Seater = 2;

   public :
		void _INIT(int _qty);


};



C#

class SizeCalculater
    {

     /* Here i have to declare 
     private every where which sucks*/

     private const int _2Seater = 1;
     private const int _3Seater =2;
     

     public void INIT(int _qty);
     

    }


As you can see declaring private or public over and over again quite frankly sucks.

I mean you don't have to type in private for all variables , that is overkill and lets me think of VB declaration . Anders Hejlsberg could have brought this feature into C#, it would have looked better and work better.

With nothing against Anders Hejlsberg, he is a inventor but this just look like the step in the wrong direction .

Just imagine how cool it would look

public class User
{

private:
   string _Name;
   string _Surname;
   string _Email;
   
public:
   string Name{get{return _Name;}}
   string Surname{get{return _Surname;}}
   string Email { get{return _Email;}}
   
   void User(string Name,
             string Surname,
             string Email) 
      {

       _Name = Name;
       _Surname = Surname;
       _Email = Email;

      }
}



This is far better.


What would you want to add to C#?

This post has been edited by marinus: 30 March 2011 - 03:57 AM


Is This A Good Question/Topic? 1
  • +

Replies To: What i would like in C# (5.0)

#2 Sergio Tapia   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1258
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: What i would like in C# (5.0)

Posted 30 March 2011 - 06:16 AM

I don't like that syntax. What happens if you need to change an access modifier from private to public? If your class is big enough you'll have to cut, scroll down and paste. Instead of just double clicking the modifier and typing in 'public'.
Was This Post Helpful? 3
  • +
  • -

#3 marinus   User is offline

  • D.I.C Addict
  • member icon

Reputation: 138
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: What i would like in C# (5.0)

Posted 30 March 2011 - 06:59 AM

Thanks for your input , Sergio


Well i will rather cut/paste the line of code than to delete 'private' and retyping in 'public'. I think it will be faster ;)

I think it might be an excellent option to have in the C# syntax ,


its just like declaring

int i,x,y;


And you can still use the old method if you want to .

This post has been edited by marinus: 30 March 2011 - 07:01 AM

Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: What i would like in C# (5.0)

Posted 30 March 2011 - 07:13 AM

Well, I see two issues with that. First is one of scope. How do you "break out" of that syntax? Does everything below public become public, including methods and properties?

Second, that's already the syntax for declaring labels for use with goto statements. Not that you should be using those, but there it is.

But really you can already get yourself halfway there, since class members are private by default, you can omit that modifier.
Was This Post Helpful? 4
  • +
  • -

#5 marinus   User is offline

  • D.I.C Addict
  • member icon

Reputation: 138
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: What i would like in C# (5.0)

Posted 30 March 2011 - 07:24 AM

Quote

How do you "break out" of that syntax?


In C++ it does not require to break out keywork but it this comment will show you how it works


{//Start class
private :

//then all is private 

//this breaks here 

public : 

//all here is public 


}//end class 



Quote

Does everything below public become public, including methods and properties?


Yes.

Really in the end what im trying to say is i don't like giving each property\method a access modifier.

Its so VB like.


I like more the way its done in the old C langauges .

thats all :)

This post has been edited by marinus: 30 March 2011 - 07:28 AM

Was This Post Helpful? 0
  • +
  • -

#6 lordofduct   User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2668
  • View blog
  • Posts: 4,786
  • Joined: 24-September 10

Re: What i would like in C# (5.0)

Posted 30 March 2011 - 07:43 AM

As an optional I could see it being nice. I personally would want a terminator for the member list.

Though I really don't have any problem with the current way C# does it.
Was This Post Helpful? 1
  • +
  • -

#7 killie01   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 66
  • Joined: 05-November 10

Re: What i would like in C# (5.0)

Posted 30 March 2011 - 09:41 AM

Quote

What would you want to add to C#?


i would like that c# writes itself :P

not really, i like prgramming

This post has been edited by killie01: 30 March 2011 - 09:41 AM

Was This Post Helpful? 0
  • +
  • -

#8 Momerath   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1021
  • View blog
  • Posts: 2,463
  • Joined: 04-October 09

Re: What i would like in C# (5.0)

Posted 30 March 2011 - 10:07 AM

I'd like to see something that handles the whole InvokeRequired/Invoke thing. Something like how using() handles disposing, maybe something like:
invoke(Control = Value);
invoke(Control = Method());
invoke(Control = Method(Parameter1, etc..)

This post has been edited by Momerath: 30 March 2011 - 01:15 PM

Was This Post Helpful? 0
  • +
  • -

#9 lordofduct   User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2668
  • View blog
  • Posts: 4,786
  • Joined: 24-September 10

Re: What i would like in C# (5.0)

Posted 30 March 2011 - 10:10 AM

well InvokeRequired/Invoke is a System.Windows.Forms thing, and not a .Net thing. So a language specific syntax would seem out of place. You could write your own utility method or even extension method to do it.
Was This Post Helpful? 0
  • +
  • -

#10 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1536
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: What i would like in C# (5.0)

Posted 30 March 2011 - 01:07 PM

As Curtis Rutland stated, you don't have to use "private". Variables are private by default. So if you don't type any modifier, it's private. Same goes for methods. No modifier means it's private.
Was This Post Helpful? 0
  • +
  • -

#11 Momerath   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1021
  • View blog
  • Posts: 2,463
  • Joined: 04-October 09

Re: What i would like in C# (5.0)

Posted 30 March 2011 - 01:18 PM

View Postlordofduct, on 30 March 2011 - 10:10 AM, said:

well InvokeRequired/Invoke is a System.Windows.Forms thing, and not a .Net thing. So a language specific syntax would seem out of place. You could write your own utility method or even extension method to do it.
async code is getting it's own keyword, so I want one for invoke :)
Was This Post Helpful? 0
  • +
  • -

#12 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: What i would like in C# (5.0)

Posted 30 March 2011 - 01:19 PM

You can check this page to see what else defaults to what:

http://msdn.microsof...y/ms173121.aspx

Quote

Classes and structs that are declared directly within a namespace...Internal is the default if no access modifier is specified.


Quote

The access level for class members and struct members, including nested classes and structs, is private by default.


Quote

Interfaces declared directly within a namespace...default to internal access. Interface members are always public

Was This Post Helpful? 0
  • +
  • -

#13 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Re: What i would like in C# (5.0)

Posted 30 March 2011 - 01:22 PM

; to be optional.
Was This Post Helpful? 0
  • +
  • -

#14 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: What i would like in C# (5.0)

Posted 30 March 2011 - 01:28 PM

Quote

; to be optional.

HERETIC!

This post has been edited by Curtis Rutland: 30 March 2011 - 01:28 PM

Was This Post Helpful? 0
  • +
  • -

#15 lordofduct   User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2668
  • View blog
  • Posts: 4,786
  • Joined: 24-September 10

Re: What i would like in C# (5.0)

Posted 30 March 2011 - 01:30 PM

View PostMomerath, on 30 March 2011 - 01:18 PM, said:

View Postlordofduct, on 30 March 2011 - 10:10 AM, said:

well InvokeRequired/Invoke is a System.Windows.Forms thing, and not a .Net thing. So a language specific syntax would seem out of place. You could write your own utility method or even extension method to do it.
async code is getting it's own keyword, so I want one for invoke :)


async isn't quite the same as WinForms. The async stuff is a design that is language wide, WinForms is not.

And if you want it now... again you could have it in relatively few lines of code:

        public static void AutoInvoke(System.Windows.Forms.Control cntrl, System.Delegate mthd, params object[] args)
        {
            if (cntrl.InvokeRequired)
            {
                cntrl.Invoke(mthd, args);
            }
            else
            {
                mthd.DynamicInvoke(args);
            }
        }



done... this hardly needs a keyword.
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »