// This is a function, where a and b are parameters static void ChangeValuesTest(int a, MyClass b) { // if I change b.AnInt , the changes will be seen on the b b.AnInt = a; // This does not change original value, because it is value type a = 6; }
static void Main(string[] args) { MyClass mc = new MyClass( ); CardDeckSettings ops = CardDeckSettings.SingleDeck | CardDeckSettings.FancyNumbers | CardDeckSettings.Animation; mc.SetOptions( ops ); mc.PrintOptions( ); }
static void Test1() { MyClass myclass = new MyClass(); myclass.AnInt = 5; int anint = 4; ChangeValuesTest(anint, myclass); // myclass.AnInt is changed! Console.WriteLine(myclass.AnInt); // anint will not be changed as it is value type Console.WriteLine(anint); Console.Read(); }
public static void Listing9_12() { Person myperson = new Person("John Doe"); int mycount = 10; Console.WriteLine("MAin Method - variables values before: {0}, {1}", myperson.Name, mycount); MyClass mc = new MyClass(); mc.MyMethod(ref myperson, ref mycount); Console.WriteLine("Main Method - variable values after: {0}, {1}", myperson.Name, mycount); Console.WriteLine("Press enter to finish"); Console.ReadLine(); }
public override object clone() { MyClass clon = new MyClass(); clon.i = this.i; clon.str = this.str; //clon.id = this.id; // passive clonning clon.id = clon.GetHashCode(); // smart clonning return clon; #region another way MyClass clon2 = (MyClass)this.MemberwiseClone(); clon2.id = clon2.GetHashCode(); return clon2; //or //return this.MemberwiseClone(); #endregion }
static void Main(string[] args) { string username = "******"; string password = "******"; Console.WriteLine("Hello " + username +", your password is :" + password); Console.WriteLine("New Password please:"); password = Console.ReadLine(); Console.WriteLine("Hello " + username + ", your new password is :" + password); Console.ReadLine(); Car car; car = new Car("Red"); Console.WriteLine(car.Describe()); Console.WriteLine("The car getter method is exposed for color: " + car.Color); car.Color = "purple"; Console.WriteLine("The car setter method is exposed for color: " + car.Color); Car car2 = new Car("Green"); Console.WriteLine(car2.Describe()); Console.ReadLine(); GreetPersons(0); GreetPersons(25, "John", "Jane", "Tarzan"); Console.ReadKey(); int number1; do { Console.WriteLine("Please enter a number(1-10):"); number1 = int.Parse(Console.ReadLine()); if ((number1 > 0) && (number1 < 11)) Console.WriteLine("Good job!"); else Console.WriteLine("Out of range.. boo"); } while ((number1 < 1) || (number1 > 10)); int result = AddNumbers(number1); Console.WriteLine("Adding ?? to your number: " + result); Console.ReadLine(); ArrayList list = new ArrayList(); list.Add("John Doe"); list.Add("Jane Doe"); list.Add("Someone Else"); foreach(string name in list) Console.WriteLine(name); Console.ReadLine(); //Class with Public methods MyClass cls = new MyClass(); Console.Write("Write a number: "); long a= Convert.ToInt64(Console.ReadLine()); // a is the number given by the user long av = cls.volteado(a); bool isTrue = cls.siprimo(a); bool isavTrue = cls.siprimo(av); Console.WriteLine("a: " + a + "av: " + av); if (isTrue == false && isavTrue == false) Console.WriteLine("Both original and swapped numbers are prime."); else Console.WriteLine("One of the numbers isnt prime."); Console.ReadLine(); Console.WriteLine("Do you enjoy C# ? (yes/no/maybe)"); string input = Console.ReadLine(); switch(input.ToLower()) { case "yes": case "maybe": Console.WriteLine("Great!"); break; case "no": Console.WriteLine("Too bad!"); break; default: Console.WriteLine("I'm sorry, I don't understand that!"); break; } Console.ReadLine(); }
public MyClassProxy() { myClass2 = new MyClass(); }
static void Main(string[] args) { MyClass mc = new MyClass(); mc.TimeUpdate(); }
static void Main(string[] args) { MyClass m1 = new MyClass(); MyClass2 m2 = new MyClass2(); MyClass3 m3 = new MyClass3(); Console.WriteLine(m1.GetHashCode() + " " + m1.id); Console.WriteLine(m2.GetHashCode() + " " + m2.id); Console.WriteLine(m3.GetHashCode() + " " + m3.id); Console.WriteLine("-----------------------"); m1 = (MyClass)m1.clone(); m2 = (MyClass2)m2.clone(); m3 = (MyClass3)m3.Clone(); Console.WriteLine("-----------------------"); Console.WriteLine(m1.GetHashCode() + " " + m1.id); Console.WriteLine(m2.GetHashCode() + " " + m2.id); Console.WriteLine(m3.GetHashCode() + " " + m3.id); }
public static void Main(string[] args) { Console.WriteLine("Введите исходную строку"); MyClass a = new MyClass(Console.ReadLine()); string buf = "3"; while (buf != "0") { switch (buf) { case "1": Console.Clear(); string old_word, new_word; Console.WriteLine("Введите слово, которое нужно заменить"); old_word = Console.ReadLine(); Console.WriteLine("Введите слово-замену"); new_word = Console.ReadLine(); a.ReplaceWords(char.ToLower(old_word[0]) + old_word.Substring(1, old_word.Length - 1), new_word); a.ReplaceWords(char.ToUpper(old_word[0]) + old_word.Substring(1, old_word.Length - 1), new_word); buf = "3"; break; case "2": Console.Clear(); Console.WriteLine("Введите искомую подстроку"); string substr = Console.ReadLine(); int k = 0; k += a.AmtOfSubstr(char.ToLower(substr[0]) + substr.Substring(1, substr.Length - 1)); k += a.AmtOfSubstr(char.ToUpper(substr[0]) + substr.Substring(1, substr.Length - 1)); Console.WriteLine("Исходная строка: " + a.St + "\n" + "Колличество вхождений подстроки \"{0}\" в строку: {1}", substr, k); Console.WriteLine("Нажмите Enter"); Console.ReadLine(); buf = "3"; break; case "3": Console.Clear(); Console.WriteLine(a.St + "\n" + "Число букв в строке: " + a.AmtOfLetters() + "\n" + "Средняя длина слова: " + a.AverageLengthOfWord()); if (a.IsPalindrome()) { Console.WriteLine("Строка является палиндромом"); } else { Console.WriteLine("Строка не является палиндромом"); } if (a.IsDate()) { Console.WriteLine("Строка является датой"); } else { Console.WriteLine("Строка не является датой"); } Console.WriteLine("Меню:\n" + "1. Заменить слова в строке на заданное\n" + "2. Найти колличество вхождений подстроки в строке\n" + "0. Выход"); buf = Console.ReadLine(); break; case "0": break; default: buf = "3"; break; } } }
// Метод создающий и тут же уничтожающий объект public void objectGenerator(int i) { MyClass ob = new MyClass(i); }
static void Main(string[] args) { MyClass mc = new MyClass(); Console.WriteLine("Hour: {0}", mc.GetHour()); }