|
|
The way I taught myself coding was to find an app, and write code to duplicate it as precisely as possible.
I often suggest trying to duplicatre Windows Notepad. That should get you reasonably comfortable in your chosen language and framework.
The only way you're going to learn it is by doing it.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I wrote a few "casino games" when starting out, like Blackjack / 21.
You learn about "collections" (of cards) and random number generation. You can get fancy with "playing card images" found on the web.
You're somewhat motivated to "beat your own game" while making the game as true to life as possible.
You'll find out that once you have the game "right", the house always wins in the long run.
If not, you go on tour.
(I've moved on to horse races since then).
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
Hi. I am a beginner with C# and tried using visual studios to make a simple program.
Console.WriteLine("What is your name: ");
string name = Console.ReadLine();
Console.WriteLine("What is your age: ");
string age = Console.ReadLine();
Console.WriteLine("What is your occupation: ");
string occupation = Console.ReadLine();
Console.WriteLine(? "{name}, is {age} years of age and he works as a {occupation}.");
The error message is CS1001 (Identifier expected) for the last line of code.
Anyone knows what is wrong?
|
|
|
|
|
|
Oh my god i completely forgot. Thank you so much. God knows i would have been stuck on it for about a week. My code works perfectly now.
|
|
|
|
|
I'm glad Richard has fixed that for you, but would you mind a suggestion?
Your code lacks what we call "validation" - which means that you don't check what the user types at all. As a result, he can enter anything he likes for "Age" and you will accept it - even if it isn't a number.
Instead of "trusting the user to get it right" it's a good idea to validate the input and check that what he entered is legit, or you will get problems later on. (It doesn't really matter for this code, but if you start to expand it then it will cause you grief).
So let's check that his Age is actually a number:
int age;
string ageInput;
do
{
Console.WriteLine("What is your age: ");
ageInput = Console.ReadLine();
} while (!int.TryParse(ageInput, out age));
What that does is sets up a loop:
do
{
...
} while (condition); which continues to go round until condition is no longer true.
Inside the loop, we prompt the user and read his response:
do
{
Console.WriteLine("What is your age: ");
ageInput = Console.ReadLine();
} while (...);
And finally we try to convert his input to an integer:
do
{
...
} while (!int.TryParse(ageInput, out age)); int.TryParse is a standard method which takes two parameters: the input string and a place to put the result (don't worry about the word out in there - you'll come to that later), then returns a boolean value (true or false ) which says "It converted OK" (true ) or "That wasn't an integer he entered" (false ). We put an exclamation mark in front of that to "reverse the decision" so that true becomes false and vice versa, so the loop goes round until we do get an integer.
Now, you can do maths with his input:
Console.WriteLine($"{name}, is {age} years of age and he works as a {occupation}.");
Console.WriteLine($"Next year, {name} will be {age + 1} years old."); because you have validated his input and are sure it's a "real number".
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
//User "$" instead of "?" sign.
Console.WriteLine($"{name}, is {age} years of age and he works as a {occupation}.");
Console.ReadKey();
|
|
|
|
|
Can you please explain
administratively scalable with examples?
Third, a system can be administratively scalable, meaning that it can still be easy to manage even if it spans many independent administrative organizations
|
|
|
|
|
|
I'm starting to detect a strong whiff of "homework" here with these two and your QA question: and the idea is that you think about the question and what you have been taught, and post your ideas; not ours. Part of the idea of homework is to get you thinking in a particular way rather than just parroting what you have been told.
Copy'n'paste from someone else doesn't teach you anything - you don't even remember what it was you copied in any detail. So if questions about this material come up in your exams you can't answer them; and future material which assumes you understand this stuff becomes a lot harder for you to work with.
So try it: read the document, review your lectures. And think about what it means then try to answer it yourself. Just getting our thoughts only helps you briefly in the short term - it damages your chances in the longer term, honest!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Can you please explain the bolded part?
When a system needs to scale, very different types of problems need to be solved. Let us first consider scaling with respect to size. If more users or resources need to be supported, we are often confronted with the limitations of centralized services, data, and algorithms (see Fig. 1-3). For example, many services are centralized in the sense that they are implemented by means of only a single server running on a specific machine in the distributed system. The problem with this scheme is obvious: the server can become a bottleneck as the number of users and applications grows. Even if we have virtually unlimited processing and storage capacity, communication with that server will eventually prohibit further growth.
modified 24-Jun-19 3:39am.
|
|
|
|
|
Don't post the same question in multiple forums.
|
|
|
|
|
In other words, hardware is always going to be the bottleneck. You can't change a user's connectivity, memory, storage, screen resolution, etc.
All you can do is make your code as efficient as possible, publish minimum acceoptable hardware, and let the user decide if their hardware is capable of runnign your app.
In terms of servers, communication performance is a) how many connections a given server can handle, b) how many hops exist between the server and the user, and finally, c) the user's hardware/software configuration. You have no control over any of that.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
|
I have this property (in a static class) - the assembly is using ,Net 4.62, and exists ina solution with other assemblies that all use 4.62:
public static MyObject MyObj { get; private set; } I'm getting a warning saying that the property isn't CLS-compliant. What makes it not CLS-compliant? (I tried removing the private accessor from the set , and it didn't have any affect.)
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I don't get a problem if I try that:
public class MyObject { }
public static class myClass
{
public static MyObject MyObj { get; private set; }
}
What am I doing that is different to you?
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
MyObject is implemented in another assembly within the same solution (and that class is itself CLS compliant), and that assembly references two other assemblies in the same solution.
I supressed the warning in the project properties, but I don't like doing that.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 20-Jun-19 11:13am.
|
|
|
|
|
I still don't get a problem - if I move the class to a new Class Library assembly, add a reference, and add the appropriate using statement, I still don't get an error or warning.
Possible difference: I'm using 4.7.2, not 4.6.2. I'll see if I can change it ...
Well, that buggered things up ... one VS restart later ... no errors, no warnings.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I found it.
I'm refactoring some code I got off GitHub and the assemblyinfo.cs file had the clscompliant setting, like so:
[assembly: CLSCompliant(true)]
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 20-Jun-19 11:33am.
|
|
|
|
|
I have a solution with two class library assemblies - TestLib1 and TestLib2.
In TestLib1, I have the following:
namespace TestLib1
{
public static partial class Globals
{
public static bool Property1 { get { return true; } }
}
} In TestLib2, I tried this:
namespace TestLib1
{
public static partial class Globals
{
public static bool Method1 { return Globals.Property1; }
}
} In TestLib2, the referece to Property1 in results in this error:
'Globals' does not contain a definition for 'Property1'
and the reference to Globals(.Property1) results in this warning:
The type 'Globals' in TestLib2\Class1.cs conflicts with the imported type 'Globals' in TestLib1.
I thought it was logical to be able to extend existing namespaces and their partial classes in assemblies that reference the assembly that contains those namespaces/classes.
I seem to remember being able to do this a few years ago, but maybe I'm remembering wrong???
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
No, you can't split a class across two assemblies because they can't be compiled together: one assembly will contain a class which the compiler considers complete, and the second will contain a different class with the same name that it also considers complete. Compilation "bakes in" the metadata that the framework uses and the class is no longer partial.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Balls. :/
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I just wish you could have abstract static bits'n'bobs ... but static methods cannot be inherited or overridden so they can't be marked abstract either.
Wrecked two days of brilliant design work for me, that did.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
yeah - an abstract static class would be a huge winner in my book. But hey, at least we get new icons in C#8.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|