Mishu Bellringer of Ostral-B
Mishu Bellringer of Ostral-B
CC#
Created by Mishu Bellringer of Ostral-B on 4/23/2023 in #help
❔ ✅ Static vs. non-Static (?)
Hello hello (: Im a very beginner, and trying to learn about delegates. But i stumbled upon the topic of Static/NonStatic - i've read about what it does; Static members dont operate on the instance of a class, but the class itself, whereas non-static members operate on the instance. (A memeber that keeps track of all the instances of a class could be static) But i'm having much trouble deciding what should be static or not, even with the information. How do i decide it? I have this example, where i feel a static-method would be more flexible in the given context - but i dont know if i should?
internal class Book
{
// - Properties - //
public string Title { get; set; }
public string Author { get; set; }

// - - Spezified Class Constructor - - //
public Book(string title, string author)
{
Title = title;
Author = author;
}

// - Defining the Delegate - Dotnet: past-tense, -Handler
public delegate void BookNotificationSendedHandler(Book notification);

// - - Methods - - //
public void NotifySMS(Book book)
{
Console.WriteLine($"SMS Send: {book.Title} written by {book.Author} is available!");
}
public static void NotifyMail(Book book)
{
Console.WriteLine($"Mail Send: {book.Title} written by {book.Author} is available!");
}
}
internal class Book
{
// - Properties - //
public string Title { get; set; }
public string Author { get; set; }

// - - Spezified Class Constructor - - //
public Book(string title, string author)
{
Title = title;
Author = author;
}

// - Defining the Delegate - Dotnet: past-tense, -Handler
public delegate void BookNotificationSendedHandler(Book notification);

// - - Methods - - //
public void NotifySMS(Book book)
{
Console.WriteLine($"SMS Send: {book.Title} written by {book.Author} is available!");
}
public static void NotifyMail(Book book)
{
Console.WriteLine($"Mail Send: {book.Title} written by {book.Author} is available!");
}
}
Book codingBook = new("C# for Beginners", "TheGreatGhostOfC#");
Book cookingBook = new("Pipebombs and soup", "NYA");

Book.BookNotificationSendedHandler notifySMS = codingBook.NotifySMS;
Book.BookNotificationSendedHandler notifyMail = Book.NotifyMail;

notifySMS(codingBook);
notifyMail(cookingBook);
Book codingBook = new("C# for Beginners", "TheGreatGhostOfC#");
Book cookingBook = new("Pipebombs and soup", "NYA");

Book.BookNotificationSendedHandler notifySMS = codingBook.NotifySMS;
Book.BookNotificationSendedHandler notifyMail = Book.NotifyMail;

notifySMS(codingBook);
notifyMail(cookingBook);
Do i decide what is static or not or do some rules i may not understand/know yet decide what should be static or not? Thanks very much in advance 🙂
9 replies
CC#
Created by Mishu Bellringer of Ostral-B on 3/1/2023 in #help
✅ Initializing 'double's maximum value; Exeption
Hello hello (: ... silly little question! Went over to C#-doc and looked up built-in data types and, for funsies, CTRL-C/V them all down and initialized em' with their biggest value. All dandy, but not for the dreaded 'double'! It threw an error. Floating-point constant is outside the range of type 'double'. Asked ChatGPT and tried finding something on the internet, and the answer was: The reason you can't initialize a double with the value of 1.79769313486232e308 is because this is the maximum value that a double can represent in C#. Which i dont truly understand! If it is the maximum-value, why cant i assign it? It works with all the other built-in data types. ): https://media.discordapp.net/attachments/1068421165086937108/1080521899760685146/image.png?width=539&height=60 https://media.discordapp.net/attachments/1068421165086937108/1080522173816524881/image.png?width=580&height=292
6 replies