+ Reply to Thread
Page 5 of 7 ... 3 4 5 6 7
Results 41 to 50 of 66

 

Thread: كتب c# باللغة الانجليزية

  • Thread Tools
  1. #41 Collapse post
    zied toumi is offline
    Banned Array
    Join Date
    Oct 2013
    Posts
    78
    Accrued Payments
    6 USD
    Thanks
    0
    Thanked 1 Time in 1 Post
    Return a Value
    Although methods with a return type of void are not rare, most methods will return a value.
    In fact, the ability to return a value is one of the most useful features of a method. You have
    already seen an example of a return value: when we used Math.Sqrt( ) to obtain a square root
    in chapters 2 and 3.
    Return values are used for a variety of purposes in programming. In some cases, such
    as with Math.Sqrt( ), the return value contains the outcome of some calculation. In other
    cases, the return value may simply indicate success or failure. In still others, it may contain
    a status code. Whatever the purpose, using method return values is an integral part of C#
    programming.
    Methods return a value to the calling routine using this form of return:
    return value;
    Here, value is the value returned.
    You can use a return value to improve the implementation of Range( ). Instead of
    displaying the range, a better approach is to have Range( ) compute the range and return
    this value. Among the advantages to this approach is that you can use the value for other
    calculations. The following example modifies Range( ) to return the range rather than
    displaying it:
    // Use a return value.
    using System;
    // A class that encapsulates information about vehicles.
    class Vehicle {
    public int Passengers; // number of passengers
    public int FuelCap; // fuel capacity in gallons
    public int Mpg; // fuel consumption in miles per gallon

    ---------- Post added at 11:17 AM ---------- Previous post was at 11:17 AM ----------

    // Return the range.
    public int Range() {
    return Mpg * FuelCap;
    }
    }
    class RetMeth {
    static void Main() {
    Vehicle minivan = new Vehicle();
    Vehicle sportscar = new Vehicle();
    int range1, range2;
    // Assign values to fields in minivan.
    minivan.Passengers = 7;
    minivan.FuelCap = 16;
    minivan.Mpg = 21;
    // Assign values to fields in sportscar.
    sportscar.Passengers = 2;
    sportscar.FuelCap = 14;
    sportscar.Mpg = 12;
    // Get the ranges.
    range1 = minivan.Range();
    range2 = sportscar.Range();

    ---------- Post added at 11:20 AM ---------- Previous post was at 11:17 AM ----------

    Console.WriteLine("Minivan can carry " + minivan.Passengers +
    " with range of " + range1 + " miles.");
    Console.WriteLine("Sportscar can carry " + sportscar.Passengers +
    " with range of " + range2 + " miles.");
    }
    }
    The output is shown here:
    Minivan can carry 7 with range of 336 miles.
    Sportscar can carry 2 with range of 168 miles.
    In the program, notice that when Range( ) is called, it is put on the right side of an
    assignment statement. On the left is a variable that will receive the value returned by Range( ).
    Thus, after this line executes,
    range1 = minivan.Range();
    the range of the minivan object is stored in range1.
    Notice that Range( ) now has a return type of int. This means that it will return an integer
    value to the caller. The return type of a method is important because the type of data returned

    ---------- Post added at 11:20 AM ---------- Previous post was at 11:20 AM ----------

    by a method must be compatible with the return type specified by the method. Thus, if you
    want a method to return data of type double, its return type must be type double.
    Although the preceding program is correct, it is not written as efficiently as it could be.
    Specifically, there is no need for the range1 or range2 variables. A call to Range( ) can be
    used in the WriteLine( ) statement directly, as shown here:
    Console.WriteLine("Minivan can carry " + minivan.Passengers +
    " with range of " + minivan.Range() + " Miles");
    In this case, when WriteLine( ) is executed, minivan.Range( ) is called automatically and its
    value will be passed to WriteLine( ). Furthermore, you can use a call to Range( ) whenever
    the range of a Vehicle object is needed. For example, this statement compares the ranges of
    two vehicles:
    if(v1.Range() > v2.Range()) Console.WriteLine("v1 has greater range");

    ---------- Post added at 11:37 AM ---------- Previous post was at 11:20 AM ----------

    Q: I have heard that C# detects “unreachable code.” What does this mean?
    A: You heard correctly. The C# compiler will issue a warning message if you create a method
    that contains code that no path of execution will ever reach. Consider this example:
    public void m() {
    char a, b;
    // ...
    if(a==b) {
    Console.WriteLine("equal");
    return;
    } else {
    Console.WriteLine("not equal");
    return;
    }
    Console.WriteLine("this is unreachable");
    }
    Here, the method m( ) will always return before the final WriteLine( ) statement is executed.
    If you try to compile this method, you will receive a warning. In general, unreachable code
    constitutes a mistake on your part, so it is a good idea to take unreachable code warnings
    seriously!

    ---------- Post added at 11:38 AM ---------- Previous post was at 11:37 AM ----------

    Use Parameters
    It is possible to pass one or more values to a method when the method is called. As explained,
    a value passed to a method is called an argument. Inside the method, the variable that receives
    the argument is called a formal parameter, or just parameter, for short. Parameters are declared
    inside the parentheses that follow the method’s name. The parameter declaration syntax is the
    same as that used for variables. The scope of a parameter is the body of its method. Aside from
    its special task of receiving an argument, it acts like any other local variable.
    Here is a simple example that uses a parameter. Inside the ChkNum class, the method
    IsEven( ) returns true if the value that it is passed is even. It returns false otherwise.
    Therefore, IsEven( ) has a return type of bool.
    // A simple example that uses a parameter.
    using System;
    // This class contains the method isEven that takes a parameter.
    class ChkNum {
    // Return true if x is even.
    public bool IsEven(int x) {
    if((x%2) == 0) return true;
    else return false;
    }
    }

    ---------- Post added at 11:44 AM ---------- Previous post was at 11:38 AM ----------

    class ParmDemo {
    static void Main() {
    ChkNum e = new ChkNum();
    if(e.IsEven(10)) Console.WriteLine("10 is even.");
    if(e.IsEven(9)) Console.WriteLine("9 is even.");
    if(e.IsEven(8)) Console.WriteLine("8 is even.");
    }
    }
    Here is the output produced by the program:
    10 is even.
    8 is even.
    In the program, IsEven( ) is called three times, and each time, a different value is passed. Let’s
    look at this process closely. First, notice how IsEven( ) is called. The argument is specified
    between the parentheses. When IsEven( ) is called the first time, it is passed the value 10. Thus,
    when IsEven( ) begins executing, the parameter x receives the value 10. In the second call, 9 is
    the argument and x then has the value 9. In the third call, the argument is 8, which is the value

    ---------- Post added at 11:47 AM ---------- Previous post was at 11:44 AM ----------

    that x receives. The point is that the value passed as an argument when IsEven( ) is called is
    the value received by its parameter, x.
    A method can have more than one parameter. Simply declare each parameter, separating
    one from the next with a comma. For example, the Factor class defines a method called
    IsFactor(( ) that determines if the first parameter is a factor of the second.
    using System;
    class Factor {
    // Determine if x is a factor of y.
    public bool IsFactor(int x, int y) {
    if( (y % x) == 0) return true;
    else return false;
    }
    }
    class IsFact {
    static void Main() {
    Factor x = new Factor();
    if(x.IsFactor(2, 20)) Console.WriteLine("2 is factor");
    if(x.IsFactor(3, 20)) Console.WriteLine("this won't be displayed");
    }
    }
    Notice that when IsFactor( ) is called, the arguments are also separated by commas.
    When using multiple parameters, each parameter specifies its own type, which can differ
    from the others. For example, this is perfectly valid:
    int MyMeth(int a, double b, float c) {
    // ...

    ---------- Post added at 11:49 AM ---------- Previous post was at 11:47 AM ----------

    Add a Parameterized Method to Vehicle
    You can use a parameterized method to add a new feature to the Vehicle class: the ability
    to compute the amount of fuel needed for a given distance. This new method is called
    FuelNeeded( ). This method takes the number of miles that you want to drive and returns the
    number of gallons of gas required. The FuelNeeded( ) method is defined like this:
    public double FuelNeeded(int miles) {
    return (double) miles / Mpg;
    }
    Notice that this method returns a value of type double. This is useful, since the amount of fuel
    needed for a given distance might not be an even number.

    ---------- Post added at 11:50 AM ---------- Previous post was at 11:49 AM ----------

    The entire Vehicle class that includes FuelNeeded( ) is shown here:
    /*
    Add a parameterized method that computes the
    fuel required for a given distance.
    */
    using System;
    class Vehicle {
    public int Passengers; // number of passengers
    public int FuelCap; // fuel capacity in gallons
    public int Mpg; // fuel consumption in miles per gallon
    // Return the range.
    public int Range() {
    return Mpg * FuelCap;
    }
    // Compute fuel needed for a given distance.
    public double FuelNeeded(int miles) {
    return (double) miles / Mpg;
    }
    }
    class CompFuel {
    static void Main() {
    Vehicle minivan = new Vehicle();
    Vehicle sportscar = new Vehicle();
    double gallons;
    int dist = 252;
    // Assign values to fields in minivan.
    minivan.Passengers = 7;
    minivan.FuelCap = 16;
    minivan.Mpg = 21;
    // Assign values to fields in sportscar.
    sportscar.Passengers = 2;
    sportscar.FuelCap = 14;
    sportscar.Mpg = 12;
    gallons = minivan.FuelNeeded(dist);
    Console.WriteLine("To go " + dist + " miles minivan needs " +
    gallons + " gallons of fuel.");
    gallons = sportscar.FuelNeeded(dist);

    Though trading on financial markets involves high risk, it can still generate extra income in case you apply the right approach. By choosing a reliable broker such as InstaForex you get access to the international financial markets and open your way towards financial independence. You can sign up here.


  2. #42 Collapse post
    zied toumi is offline
    Banned Array
    Join Date
    Oct 2013
    Posts
    78
    Accrued Payments
    6 USD
    Thanks
    0
    Thanked 1 Time in 1 Post
    Console.WriteLine("To go " + dist + " miles sportscar needs " +
    gallons + " gallons of fuel.");
    }
    }
    The output from the program is shown here:
    To go 252 miles minivan needs 12.0 gallons of fuel.
    To go 252 miles sportscar needs 21.0 gallons of fuel.
    Create a Help Class
    If one were to try to summarize the essence of the class in a single sentence, it might be this:
    A class encapsulates functionality. Of course, sometimes the trick is knowing where one
    “functionality” ends and another begins. As a general rule, you will want your classes to be
    the building blocks of your larger application. To do this, each class must represent a single
    functional unit that performs clearly delineated actions. Thus, you will want your classes to
    be as small as possible—but no smaller! That is, classes that contain extraneous functionality
    confuse and destructure code, but classes that contain too little functionality are fragmented.
    What is the balance? It is at this point that the science of programming becomes the art of
    programming. Fortunately, most programmers find that this balancing act becomes easier
    with experience.

    ---------- Post added at 12:10 PM ---------- Previous post was at 12:03 PM ----------

    To begin gaining that experience, we will convert the help system developed in the Try
    This sections in Chapter 3 into a help class. Let’s examine why this is a good idea. First, the
    help system defines one logical unit. It simply displays the syntax for C#’s control statements.
    Thus, its functionality is compact and well defined. Second, putting help in a class is an
    aesthetically pleasing approach. Whenever you want to offer the help system to a user, simply
    instantiate a help-system object. Finally, because help is encapsulated, it can be upgraded or
    changed without causing unwanted side effects in the programs that use it.
    Step by Step
    1. Create a new file called HelpClassDemo.cs. To save you some typing, you might want to
    copy the file from the final Try This section in Chapter 3, Help3.cs, into HelpClassDemo.cs.
    2. To convert the help system into a class, you must first determine precisely what constitutes
    the help system. For example, in Help3.cs, there is code to display a menu, input the
    user’s choice, check for a valid response, and display information about the item selected.
    The program also loops until a q is pressed. If you think about it, it is clear that the menu,
    the check for a valid response, and the display of the information are integral to the help
    system. How user input is obtained and whether repeated requests should be processed
    are not integral. Thus, you will create a class that displays the help information and the
    help menu and that checks for a valid selection. This functionality can be organized into
    methods, called HelpOn( ), ShowMenu( ), and IsValid( ).

    ---------- Post added at 12:10 PM ---------- Previous post was at 12:10 PM ----------

    3. Create the HelpOn( ) method, as shown here:
    public void HelpOn(char what) {
    switch(what) {
    case '1':
    Console.WriteLine("The if:\n");
    Console.WriteLine("if(condition) statement;");
    Console.WriteLine("else statement;");
    break;
    case '2':
    Console.WriteLine("The switch:\n");
    Console.WriteLine("switch(expression) {");
    Console.WriteLine(" case constant:");
    Console.WriteLine(" statement sequence");
    Console.WriteLine(" break;");
    Console.WriteLine(" // ...");
    Console.WriteLine("}");
    break;
    case '3':
    Console.WriteLine("The for:\n");
    Console.Write("for(init; condition; iteration)");
    Console.WriteLine(" statement;");
    break;
    case '4':
    Console.WriteLine("The while:\n");
    Console.WriteLine("while(condition) statement;");
    break;
    case '5':
    Console.WriteLine("The do-while:\n");
    Console.WriteLine("do {");
    Console.WriteLine(" statement;");
    Console.WriteLine("} while (condition);");
    break;
    case '6':
    Console.WriteLine("The break:\n");
    Console.WriteLine("break; or break label;");
    break;
    case '7':
    Console.WriteLine("The continue:\n");
    Console.WriteLine("continue; or continue label;");
    break;
    case '8':
    Console.WriteLine("The goto:\n");
    Console.WriteLine("goto label;");
    break;
    }
    Console.WriteLine();
    }

    ---------- Post added at 12:16 PM ---------- Previous post was at 12:10 PM ----------

    4. Create the ShowMenu( ) method:
    public void ShowMenu() {
    Console.WriteLine("Help on:");
    Console.WriteLine(" 1. if");
    Console.WriteLine(" 2. switch");
    Console.WriteLine(" 3. for");
    Console.WriteLine(" 4. while");
    Console.WriteLine(" 5. do-while");
    Console.WriteLine(" 6. break");
    Console.WriteLine(" 7. continue");
    Console.WriteLine(" 8. goto\n");
    Console.Write("Choose one (q to quit): ");
    }
    5. Create the IsValid( ) method, shown here:
    public bool IsValid(char ch) {
    if(ch < '1' | ch > '8' & ch != 'q') return false;
    else return true;
    }

    ---------- Post added at 12:39 PM ---------- Previous post was at 12:16 PM ----------

    6. Assemble the foregoing methods into the Help class, shown here:
    class Help {
    public void HelpOn(char what) {
    switch(what) {
    case '1':
    Console.WriteLine("The if:\n");
    Console.WriteLine("if(condition) statement;");
    Console.WriteLine("else statement;");
    break;
    case '2':
    Console.WriteLine("The switch:\n");
    Console.WriteLine("switch(expression) {");
    Console.WriteLine(" case constant:");
    Console.WriteLine(" statement sequence");
    Console.WriteLine(" break;");
    Console.WriteLine(" // ...");
    Console.WriteLine("}");
    break;
    case '3':
    Console.WriteLine("The for:\n");
    Console.Write("for(init; condition; iteration)");
    Console.WriteLine(" statement;");
    break;
    case '4':
    Console.WriteLine("The while:\n");
    Console.WriteLine("while(condition) statement;");
    break;

    ---------- Post added at 12:43 PM ---------- Previous post was at 12:39 PM ----------

    case '5':
    Console.WriteLine("The do-while:\n");
    Console.WriteLine("do {");
    Console.WriteLine(" statement;");
    Console.WriteLine("} while (condition);");
    break;
    case '6':
    Console.WriteLine("The break:\n");
    Console.WriteLine("break; or break label;");
    break;
    case '7':
    Console.WriteLine("The continue:\n");
    Console.WriteLine("continue; or continue label;");
    break;
    case '8':
    Console.WriteLine("The goto:\n");
    Console.WriteLine("goto label;");
    break;
    }
    Console.WriteLine();
    }
    public void ShowMenu() {
    Console.WriteLine("Help on:");
    Console.WriteLine(" 1. if");
    Console.WriteLine(" 2. switch");
    Console.WriteLine(" 3. for");
    Console.WriteLine(" 4. while");
    Console.WriteLine(" 5. do-while");
    Console.WriteLine(" 6. break");
    Console.WriteLine(" 7. continue");
    Console.WriteLine(" 8. goto\n");
    Console.Write("Choose one (q to quit): ");
    }

    ---------- Post added at 01:07 PM ---------- Previous post was at 12:43 PM ----------

    public bool IsValid(char ch) {
    if(ch < '1' | ch > '8' & ch != 'q') return false;
    else return true;
    }
    }
    7. Finally, create a class called HelpClassDemo.cs that uses the new Help class. Have Main( )
    display help information until the user enters q. The entire listing for HelpClassDemo.cs is
    shown here:
    // The Help system from Chapter 3 converted into a Help class.
    using System;

    ---------- Post added at 01:07 PM ---------- Previous post was at 01:07 PM ----------

    class Help {
    public void HelpOn(char what) {
    switch(what) {
    case '1':
    Console.WriteLine("The if:\n");
    Console.WriteLine("if(condition) statement;");
    Console.WriteLine("else statement;");
    break;
    case '2':
    Console.WriteLine("The switch:\n");
    Console.WriteLine("switch(expression) {");
    Console.WriteLine(" case constant:");
    Console.WriteLine(" statement sequence");
    Console.WriteLine(" break;");
    Console.WriteLine(" // ...");
    Console.WriteLine("}");
    break;
    case '3':
    Console.WriteLine("The for:\n");
    Console.Write("for(init; condition; iteration)");
    Console.WriteLine(" statement;");
    break;
    case '4':
    Console.WriteLine("The while:\n");
    Console.WriteLine("while(condition) statement;");
    break;

    ---------- Post added at 01:08 PM ---------- Previous post was at 01:07 PM ----------

    case '5':
    Console.WriteLine("The do-while:\n");
    Console.WriteLine("do {");
    Console.WriteLine(" statement;");
    Console.WriteLine("} while (condition);");
    break;
    case '6':
    Console.WriteLine("The break:\n");
    Console.WriteLine("break; or break label;");
    break;
    case '7':
    Console.WriteLine("The continue:\n");
    Console.WriteLine("continue; or continue label;");
    break;
    case '8':
    Console.WriteLine("The goto:\n");
    Console.WriteLine("goto label;");
    break;
    }
    Console.WriteLine();
    }

    Though trading on financial markets involves high risk, it can still generate extra income in case you apply the right approach. By choosing a reliable broker such as InstaForex you get access to the international financial markets and open your way towards financial independence. You can sign up here.


  3. #43 Collapse post
    zied toumi is offline
    Banned Array
    Join Date
    Oct 2013
    Posts
    78
    Accrued Payments
    6 USD
    Thanks
    0
    Thanked 1 Time in 1 Post
    class HelpClassDemo {
    static void Main() {
    char choice;
    Help hlpobj = new Help();
    for(; {
    do {
    hlpobj.ShowMenu();
    do {
    choice = (char) Console.Read();
    } while(choice == '\n' | choice == '\r');
    } while( !hlpobj.IsValid(choice) );
    if(choice == 'q') break;
    Console.WriteLine("\n");
    hlpobj.HelpOn(choice);
    }
    }
    }
    When you try the program, you will find that it is functionally the same as the final version
    in Chapter 3. The advantage to this approach is that you now have a help system component
    that can be reused whenever it is needed.
    Constructors
    In the preceding examples, the instance variables of each Vehicle object had to be set manually
    using a sequence of statements, such as:
    minivan.Passengers = 7;
    minivan.FuelCap = 16;
    minivan.Mpg = 21;
    An approach like this would never be used in professionally written C# code. Aside from
    being error-prone (you might forget to set one of the fields), there is simply a better way to
    accomplish this task: the constructor.
    A constructor initializes an object when it is created. It has the same name as its class and
    is syntactically similar to a method. However, constructors have no explicit return type. The
    general form of a constructor is shown here:
    access class-name(param-list) {
    // constructor code
    }
    Typically, you will use a constructor to give initial values to the instance variables defined by
    the class, or to perform any other startup procedures required to create a fully formed object.
    Often, access is public because a constructor is usually called from outside its class. The
    parameter-list can be empty, or it can specify one or more parameters.
    All classes have constructors, whether you define one or not, because C# automatically
    provides a default constructor that causes all member variables to be initialized to their default
    values. For most value types, the default value is zero. For bool, the default is false. For
    reference types, the default is null. However, once you define your own constructor, the default
    constructor is no longer used.
    Here is a simple example that uses a constructor:

    ---------- Post added at 01:09 PM ---------- Previous post was at 01:08 PM ----------

    // A simple constructor.
    using System;
    class MyClass {
    public int x;
    public MyClass() {
    x = 10;
    }
    }
    class ConsDemo {
    static void Main() {
    MyClass t1 = new MyClass();
    MyClass t2 = new MyClass();
    Console.WriteLine(t1.x + " " + t2.x);
    }
    }
    In this example, the constructor for MyClass is
    public MyClass() {
    x = 10;
    }
    Notice that the constructor is specified as public because the constructor will be called from
    code defined outside of its class. As mentioned, most constructors are declared public for
    this reason. This constructor assigns the instance variable x of MyClass the value 10. The
    constructor is called by new when an object is created. For example, in the line
    MyClass t1 = new MyClass();
    the constructor MyClass( ) is called on the t1 object, giving t1.x the value 10. The same is
    true for t2. After construction, t2.x has the value 10. Thus, the output from the program is
    10 10

    Though trading on financial markets involves high risk, it can still generate extra income in case you apply the right approach. By choosing a reliable broker such as InstaForex you get access to the international financial markets and open your way towards financial independence. You can sign up here.


  4. #44 Collapse post
    imaddine1986 is offline
    خبير فوركس مصر Array
    Join Date
    Nov 2012
    Posts
    2,844
    Accrued Payments
    331 USD
    Thanks
    0
    Thanked 15 Times in 15 Posts
    SubscribeSubscribe
    subscribed 0
    اولا شكرا على الموضوع
    اخي هذا المنتدى مختص باللغة العربية كان افضل ان تقدم ملخص بالغة العربية
    وترد على استفسارات الاعضاء افضل او تكتفي بوضع الكتاب للتحميل

    Though trading on financial markets involves high risk, it can still generate extra income in case you apply the right approach. By choosing a reliable broker such as InstaForex you get access to the international financial markets and open your way towards financial independence. You can sign up here.


  5. #45 Collapse post
    sondes is offline
    خبير فوركس مصر Array
    Join Date
    Oct 2013
    Posts
    2,713
    Accrued Payments
    337 USD
    Thanks
    13
    Thanked 284 Times in 231 Posts
    SubscribeSubscribe
    subscribed 0
    السلام علكم ورحمة الله وبركاته
    هذا الموقع بلغة العربية ارجاء إستعمل هاته الاغ انها سهلا جدا وشكراً علي لتفاهم

    Though trading on financial markets involves high risk, it can still generate extra income in case you apply the right approach. By choosing a reliable broker such as InstaForex you get access to the international financial markets and open your way towards financial independence. You can sign up here.


  6. #46 Collapse post
    zied toumi is offline
    Banned Array
    Join Date
    Oct 2013
    Posts
    78
    Accrued Payments
    6 USD
    Thanks
    0
    Thanked 1 Time in 1 Post
    Parameterized Constructors
    In the preceding example, a parameterless constructor was used. While this is fine for some
    situations, most often, you will need a constructor that accepts one or more parameters.
    Parameters are added to a constructor in the same way that they are added to a method: Just
    declare them inside the parentheses after the constructor’s name. For example, here, MyClass
    is given a parameterized constructor:
    // A parameterized constructor.
    using System;
    class MyClass {
    public int x;
    public MyClass(int i) {
    x = i;
    }
    }
    class ParmConsDemo {
    static void Main() {
    MyClass t1 = new MyClass(10);

    ---------- Post added at 03:14 PM ---------- Previous post was at 03:12 PM ----------

    MyClass t2 = new MyClass(88);
    Console.WriteLine(t1.x + " " + t2.x);
    }
    }
    The output from this program is shown here:
    10 88
    In this version of the program, the MyClass( ) constructor defines one parameter called i,
    which is used to initialize the instance variable, x. Thus, when this line executes,
    MyClass t1 = new MyClass(10);
    the value 10 is passed to i, which is then assigned to x.
    Add a Constructor to the Vehicle Class
    We can improve the Vehicle class by adding a constructor that automatically initializes the
    Passengers, FuelCap, and Mpg fields when an object is constructed. *** special attention to
    how Vehicle objects are created.
    // Add a constructor to Vehicle.

    ---------- Post added at 04:00 PM ---------- Previous post was at 03:14 PM ----------

    using System;
    class Vehicle {
    public int Passengers; // number of passengers
    public int FuelCap; // fuel capacity in gallons
    public int Mpg; // fuel consumption in miles per gallon
    // This is a constructor for Vehicle.
    public Vehicle(int p, int f, int m) {
    Passengers = p;
    FuelCap = f;
    Mpg = m;
    }
    // Return the range.
    public int Range() {
    return Mpg * FuelCap;
    }
    // Compute fuel needed for a given distance.
    public double FuelNeeded(int miles) {
    return (double) miles / Mpg;
    }
    }

    ---------- Post added at 10:42 PM ---------- Previous post was at 04:00 PM ----------

    Destructors
    It is possible to define a method that will be called just prior to an object’s final destruction
    by the garbage collector. This method is called a destructor, and it can be used in some highly
    specialized situations to ensure that an object terminates cleanly. For example, you might use a
    destructor to ensure that a system resource owned by an object is released. It must be stated at
    the outset that destructors are a very advanced feature that are applicable to certain specialized
    situations. They are not normally needed. However, because they are part of C#, they are
    briefly described here for completeness.
    Destructors have this general form:
    ~class-name( ) {
    // destruction code
    }
    Here, class-name is the name of the class. Thus, a destructor is declared like a constructor,
    except that it is preceded with a ~ (tilde). Notice it has no return type.
    It is important to understand that the destructor is called just prior to garbage collection.
    It is not called when a variable containing a reference to an object goes out of scope, for
    example. (This differs from destructors in C++, which are called when an object goes out
    of scope.) This means that you cannot know precisely when a destructor will be executed.
    Furthermore, it is possible for your program to end before garbage collection occurs, so a
    destructor might not get called at all.

    ---------- Post added at 10:43 PM ---------- Previous post was at 10:42 PM ----------

    The this Keyword
    Before concluding this chapter, it is necessary to introduce this. When a method is called, it is
    automatically passed a reference to the invoking object (that is, the object on which the method
    is called). This reference is called this. Therefore, this refers to the object on which the method
    is acting. To understand this, first consider a program that creates a class called Pwr that
    computes the result of a number raised to some integer power:
    using System;
    class Pwr {
    public double b;
    public int e;
    public double val;
    public Pwr(double num, int exp) {
    b = num;
    e = exp;
    val = 1;
    for( ; exp>0; exp--) val = val * b;
    }

    Though trading on financial markets involves high risk, it can still generate extra income in case you apply the right approach. By choosing a reliable broker such as InstaForex you get access to the international financial markets and open your way towards financial independence. You can sign up here.


  7. #47 Collapse post
    doola2020 is offline
    ***البروفيسير*** Array
    Join Date
    Jun 2013
    Location
    بلبيس
    Posts
    18,262
    Accrued Payments
    2034 USD
    Thanks
    15
    Thanked 262 Times in 222 Posts
    طبعا الموضوع مية في المية منقول ولكن يا أخي إن أردت أن تنقل موضوع من الخارج حتي انقل موضوع يكون باللغة العربية عشان ميبانش مثلا

    Though trading on financial markets involves high risk, it can still generate extra income in case you apply the right approach. By choosing a reliable broker such as InstaForex you get access to the international financial markets and open your way towards financial independence. You can sign up here.


  8. #48 Collapse post
    AshrafQassim is offline
    Banned Array
    Join Date
    Sep 2013
    Location
    مصر الحبيبة
    Posts
    788
    Accrued Payments
    73 USD
    Thanks
    0
    Thanked 3 Times in 3 Posts
    انا باقترح اقتراح وهو ان يكون التعلم ف البرمجة من خلال الفيديو وده تلاقه متوفر بكثر على اليوتيوب وبياخدك
    من تحت الصفر حتى الاحتراف ومن اول ما تسطب البرنامج لغاية ما تصصم البرامج بنفسك

    Though trading on financial markets involves high risk, it can still generate extra income in case you apply the right approach. By choosing a reliable broker such as InstaForex you get access to the international financial markets and open your way towards financial independence. You can sign up here.


  9. #49 Collapse post
    tijikawa is offline
    عضو نشيط Array
    Join Date
    Oct 2013
    Posts
    128
    Accrued Payments
    0 USD
    Thanks
    0
    Thanked 0 Times in 0 Posts
    SubscribeSubscribe
    subscribed 0
    نعم يا اخي

    Though trading on financial markets involves high risk, it can still generate extra income in case you apply the right approach. By choosing a reliable broker such as InstaForex you get access to the international financial markets and open your way towards financial independence. You can sign up here.


  10. #50 Collapse post
    WASEM DALLOUL is offline
    خبير فوركس مصر Array
    Join Date
    May 2013
    قابلت الضيوف
    3 (ضيف فوركس مصر)
    Posts
    14,774
    Accrued Payments
    1641 USD
    Thanks
    189
    Thanked 329 Times in 272 Posts
    SubscribeSubscribe
    subscribed 0
    السلام عليكم
    لغة السي لغة جيده جدا ومهمة جدا وهي تفيدنا في برمجة المؤشرات والأكسبيرتات التي نستخدمها في تجارتنا في الفوركس

    Though trading on financial markets involves high risk, it can still generate extra income in case you apply the right approach. By choosing a reliable broker such as InstaForex you get access to the international financial markets and open your way towards financial independence. You can sign up here.


+ Reply to Thread
Page 5 of 7 ... 3 4 5 6 7

Subscribe to this Thread (2)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Threads

Posts

Members