Page 1 of 3
C# Beginner
Posted: 04 May 2010, 00:14
by Wisse
I'm trying to learn C# lately and I would like some advice on how to approach this, since I find it utterly confusing.
I first started coding this year at uni. Sice I'm mechanical engineer we don't even have lectures on programing, just some brief overview. We started with C, where we had a very good mentor which thought us well for measly 30h course. C was fun, we got 2 page cheat sheet and that was more or less all I needed for my console applications. The biggest thing I did was "battleship algorithm". We each made one and then made them fight. My won btw
In February we started with C#. We got different mentor this time, who, honestly, sucked. Considering he only had 16h to teach us, you can imagine how "extensive" my knowledge is.
I'm still confused about stuff like "constructors", "classes", "encapsulation", and so on, but that's up to me to figure out. My biggest problem now is SHITLOADS of methods and members and dunno what you call it... Commands are even more absurd than words in German language. As you know you often get something like this: Xxx.Yyy.Zzz(Jjj.Iii()) which is far beyond me atm.
I wonder:
How does one get to know all of those members in C#?
Where to start?
Today I spent 3h on 15 (!) working lines of code. When I wanted to make something specific and exactly what I envisioned in my head I just got stuck completely. This is not going anywhere. Plz help, any non-troll advice will do
Thx
Re: C# Beginner
Posted: 04 May 2010, 00:34
by knorke
you often get something like this: Xxx.Yyy.Zzz(Jjj.Iii()) which is far beyond me atm.
if long statements confuse you, try to break it down into parts. Like for
Xxx.Yyy.Zzz(Jjj.Iii())
->
bla = Jjj.Iii()
Xxx.Yyy.Zzz (bla)
How does one get to know all of those members in C#?
the interweb. its no shame to always have some documentation/reference site opend. if you have an editor that suggests text, that can also be usefull.
Re: C# Beginner
Posted: 04 May 2010, 00:52
by Wisse
knorke wrote:if long statements confuse you, try to break it down into parts. Like for
Xxx.Yyy.Zzz(Jjj.Iii())
->
bla = Jjj.Iii()
Xxx.Yyy.Zzz (bla)
But I'm still left with Xxx.Yyy.Zzz -.-
I guess I'll have to soldier on...
the interweb. its no shame to always have some documentation/reference site opend. if you have an editor that suggests text, that can also be usefull.
I use VS2010. As far as I know you can't go much better for C#.
Re: C# Beginner
Posted: 04 May 2010, 01:15
by knorke
But I'm still left with Xxx.Yyy.Zzz -.-
is that part of c# or your own class design? maybe rethink it if you often come across similiar stuff...
Re: C# Beginner
Posted: 04 May 2010, 01:29
by AF
Or
Code: Select all
Y y = Xxx.Yyy;
L l = J.Lll();
y.Zzz(l);
The problem with your Xxx.Yyy.Zzz is that what if Yyy is null? How are you meant to figure that out from a line number without mousing over each and every variable in the debugger? Separate different steps into their own lines of code, from there on simplifications become more apprant that can remove intermediate steps
Re: C# Beginner
Posted: 04 May 2010, 10:20
by Wisse
I'm talking about stuff like this:
Code: Select all
int Dolzina = comboBox1.Text.Length;
I managed to figure out that I should go for .Text and then .Length here, but in most cases I'm more or less lost.
When I write comboBox1 and hit that magic "." I get auto complete up with shitloads of choices. I can't figure out what I need at that point (especially for first choice). I know everything is described nicely, but I still can't find what I want.
For example I set comboBox to already contain some text when program starts, but text was selected. So I wanted to deselect that text and put cursor at the end of it, so user can start typing away, but I failed. I just couldn't figure out what to use.
That went on whenever I wanted to do something that I couldn't deduce right away.
I guess I'll have to spend several hundred hours browsing help, just to get some idea about C#, before I can start programming properly.
Re: C# Beginner
Posted: 04 May 2010, 10:23
by ==Troy==
You better off learning C++ than C#, especially since they are quite similar, while C# requires you to have MS runtime (read it as : you cant do ANY programming besides on windows/compatible, especially I have not seen many microchips running C#, which is, considering that you are an engineer, you will be faced with in the future)
Re: C# Beginner
Posted: 04 May 2010, 10:53
by AF
Rival window UI kits tend to be vastly superior to C# winforms in terms of usability in my experience
Re: C# Beginner
Posted: 04 May 2010, 11:56
by Licho
Wisse, you are not asking how to learn C# - thats simple matter of learning syntax and core concepts common to all OO languages (+ specialities like lambdas, delegates and LINQ) .
You are asking how to learn .NET framework - which is set of powerful libraries that provide basic functions. Learning .NET takes probably years of experience.
Answer is:
* books (you should pick specialized area - like windows.forms if you want to do GUI stuff)
* MSDN
http://msdn.microsoft.com/en-us/library ... .form.aspx
* trying to guess it and using intellisense which auto fills available properties etc
* you can also ctrl+click any class to view its condensed documentation in VS object browser
Re: C# Beginner
Posted: 04 May 2010, 12:56
by hoijui
you should never leave variables at the default names, like
comboBox1, always give them meaningful names, like
emplyeeNames_sel instead, and do that right when you create them, not some-when later
what happens when a field gets focus, is usually handled by a special class (handler). Usually you should not change stuff like this, as it may confuse the user if stuff works different in your application then in others.
Also, do not start to learn C++ instead of C#. It is much uglier, which is surely not what you want as a beginner.
And C# stuff can be run under linux with Mono, as is done with SpringDownloader, for example.
Re: C# Beginner
Posted: 04 May 2010, 13:25
by ==Troy==
hoijui wrote:
And C# stuff can be run under linux with Mono, as is done with SpringDownloader, for example.
How are you supposed to fit in MONO + your program code onto a chip with 12KB ROM?

Re: C# Beginner
Posted: 04 May 2010, 13:46
by Satirik
it's just like googling ... you want the combo selected item text length ? combo.selec ... auto completion is empty ... combo.item ... empty/ or not ... combo.text ... NOT EMPTY ... etc you should be happy to have a good working auto completion, otherwise you'd have to check the documentation or even the code for every single thing you want to do
Re: C# Beginner
Posted: 04 May 2010, 13:47
by Beherith
I tend to think you should first get to grips with OO basics before trying to learn an entire library based on OO concepts.
Re: C# Beginner
Posted: 04 May 2010, 13:53
by hoijui
As he is doing GUI stuff with C#, how do you come to the conclusion that he wants to put it on a chip with 12K ROM?
+1 to what Behe said. GUI stuff is generally quite complex, better do some OO tutorials with stuff like:
Code: Select all
interface Vehicle
class Engine
class Bicycle (is a) Vehicle
class Car (is a) Vehicle (has a) Engine
Re: C# Beginner
Posted: 04 May 2010, 14:10
by ==Troy==
The thing about learning a new language is simple.
There are "hard" languages, i.e. C/C++, and the "dumbed down" languages, i.e. Java, C#, etc.
There difference is that first ones work everywhere, but require clear head to code and knowing what you are doing.
The latter ones allow you to piss around, while still making the code compile, but they require you to have runtime, bulky libraries, and not very well working code.
OO code is better to learn from C++ since you get to meet nasty things as cleaning up after yourself, and working with memory without protection. This will develop a good set of habits for the programmer, and will allow you to easily pick up any "dumbed down" language, whether it doesnt easily work backwards.
At least the approach C++ -> C# will stop the slew of shitty developers which learned C# in the uni, and then facing all of the harsh problems of C++ development. (read : code filled with buffer overflows and null pointers)
Although he is doing GUI now, as an engineer (I agree, not exactly mechanical, but even they meet some) most of the programming is done for the chips, on the chips. Because you have most of the programs you neeed on the PC already done for you.
And if you are going for coding solely on PC and solely GUI, learn python, its simpler and easier, and is more popular language afaik in the science world.
Re: C# Beginner
Posted: 04 May 2010, 14:23
by zwzsg
There are "hard" languages, i.e. C/C++, and the "dumbed down" languages, i.e. Java, C#, etc.
Meh, the distinction isn't about hardness but between coding languages, and plumbing languages. I find coding easier than plumbing. Java and C# are much harder than their reputation because of all the overheard of learning the gigantic librairies.
Then it's not like I have any Java or C# experience so I'm just dumping scorn and hatred based on misconceptions.
Re: C# Beginner
Posted: 04 May 2010, 14:51
by Satirik
it's called high level and low level languages ... and last time i checked there wasn't a program for everything on pc ... and most programming is done for pc ...
Re: C# Beginner
Posted: 04 May 2010, 14:56
by ==Troy==
Satirik wrote:it's called high level and low level languages ... and last time i checked there wasn't a program for everything on pc ... and most programming is done for pc ...
We are speaking about engineering field, where you have a standard set of programs which are accepted amongst most of the employers, and you will not have to write anything for yourself for most part of it.
Last time I checked low level programming language was called Assembler/alike. And C++ was counted as high level one.
Re: C# Beginner
Posted: 04 May 2010, 15:14
by Das Bruce
There has been inflation since you last checked.
Re: C# Beginner
Posted: 04 May 2010, 15:40
by zwzsg
And last time I checked, C was counting as low level language when used in the context of embedded system where you interface directly with the hardware.
Satirik wrote:it's called high level and low level languages ...
I find the denomination "low" and "high" discriminative. These are heavily charged words, implying that some programming language are "above" others. It is because of that kind of prejudice that the so called "low level" languages are kept in ghettos where young programmers are detered from looking instead of being allowed the role they ought to play in society.