Wisse wrote: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
C# is basically java. I don't understand specifically what is causing you problems...
In terms of stuff.otherstuff(thing, otherthing). When we make a class in C#, it works like a mold that objects go into and take that shape, and the class is not used in runtime, only the objects. so "stuff" is the name we've given the object we want to use "otherstuff" is the name of some method in the class definition of our "stuff" object. A method is a little chunk of code that does something using data we put into it, or data it already has access to from the object the method belongs to. Methods either change the state of the object they belong to, or they return some data, usually about that object. the "(thing, otherthing)" are pieces of data we are putting into the method from the outside. Methods can return any type of data, even other object, in fact, for complex programs we use methods to almost ONLY return other objects. so, if the return item for "stuff.otherstuff(thing, otherthing)" is a another object, then you can have things like "stuff.otherstuff(thing, otherthing).doADance(anObjectAsAnInputVariable.theMethod(someOtherInput))". This object is some item that takes 2 input variables and returns an object, and on the object we are having returned, we want it to doADance, but dancing requires information about another object, so we put in a reference to the input variable object method "theMethod" which returns an object.
Objects can store data as well, and the data an object stores can be another object. For example, in a window program, maby we want text boxes to be another object stored within our window object.
for the code "object.item;" if "item" is an int, then "object.item" is the int stored in the object. And we can do things like "object.item + 5 = object.item;". But item doesn't have to be a raw variable, it can be another object.
"window.textbox.entertext("hello");" in the window object, there is an textbox object we have public access to, and we want to run the method of the textbox object called "entertext" and we are inputing a string that says "hello" into entertext, which is the method of the object textbox, which is a public object contained within the object window.
It seems alot of your problem is that you're working with a library of objects someone else made and you're not really sure how they work... That's not really an intricacy of the programming language, you need to look up the library specifications and see what items in that library will do the tasks you want them to. You can code in C# without using any external libraries at all. The whole point of a library is it does abstract stuff for you that would take FOREVER to code up from scratch, and you don't have to solve all the problems the library already solved, you just have to take the time to learn how to use the parts of the library you need. It may be confusing, but it's much much faster than coding it yourself.
I wonder:
How does one get to know all of those members in C#?
Where to start?
Like I say, it's not a "member of C#" it's a library you are working with, and the simple answer is that the first time you use a new library it takes forever to figure out how it works. There's no shortcut. You just have to slog through the documentation and try to understand what it is telling you. It's just like a library with books, the codes on the books sort of help you find the kind of book you want to look at... but to learn the whole library well enough to be able to find a specific quote in a specific book just takes time to learn the way the systems work.
Start by just doing the work slowly. The first time, maby you make a window with some buttons, and it takes you 4 hours just to make the window and buttons... but the next time you do it, most of the problems you solved as to how to make the behaviors and specifications work for you, you're familiar with those books in the library already, you have an idea of how they work, it takes much much less time to find them again and much much less time to get to the parts you want to read. Just add new items to your vocabulary from that library as you need them. If you are going in with the goal of learning the library well, if you know there is a different way of doing something from the way you already know, go out of your way to dig through the library and try to find it. If it's more a case of wanting to just get done stuff fast, once you master something, when you come across a problem where you can use the information you already know to solve it, don't get fancy, just use that information.