Search This Blog

Showing posts with label CSharp. Show all posts
Showing posts with label CSharp. Show all posts

Link to download source code of the app 'Generate code for asp mvc net'

Features:
  • Allow to generate code asp mvc net from template excel ( desc about functions, tables, description of function uis)
  • Features of generated app:
  • + Allow to add, edit, remove data by modal dialog, ajax
    + Allow to grant permissions: add, edit, remove, search
    + Allow to use in smartphone
    + Allow to select functions by menu
    + Allow to show excel report or invoice printing
    + Allow to change ui language ( default is vietnamese)
  • Allow to show text resources to edit language of ui
  • Only update class source if is defferent
  • Excel Template to generate code is easy to read and edit
  • Generated code is beutiful, easy to read and understand
Link download:
Contact: tlkhoa@gmail.com
Share:

Flow Control and Looping Statements in java, javsscript, c#

 Flow control statements determine the next statement to execute. In this sense, the statements if-else, if, switch, while, for are flow control statements.
Conditional Statements:
    Conditional statements control whether a part of a script is executed depending the result of a particular expression (i.e. whether an expression returns a boolean true or false value). The two types of conditional structures are if and if ... else. In this section we will take a closer look at both of these conditional structures and provide some examples of their use.
Syntax:
if (condition)
{
   ...
} else if (condition1)
{
   ...
} else
{
   ...
}

Example: ( in javascript )
if (customerName == "Fred")
{
      document.write ("Hello Fred!");
} 
else if (customerName == "John")
{
      document.write ("Hello John!");
} 
else
{
      document.write ("You're not Fred! Where's Fred?");
}

Looping Statements:
1. for loops
Syntax:
for ( ''initializer''; ''conditional expression''; ''loop expression'' )
{
      statements to be executed
}

The initializer typically initializes a counter variable. Traditionally the variable i is used for this purpose. For example:
i = 0

This sets the counter to be the value i and sets it to zero.

The conditional expression specifies the test to perform to verify whether the loop has been performed the required number of times. For example, if we want to loop 100 times:

i < 100

Finally the loop expression specifies the action to perform on the counter variable. For example to increment by 1:

i++

Bringing this all together we can create a for loop to perform the task outlined in the earlier example:

var j = 10;

for (i=0; i<10; i++)
{
      j += j;
}

2. while loops: The for loop described above works well when you know how many times a particular task needs to be repeated. Clearly there will often be instances where something needs to be repeated until a certain condition is met, with no way of knowing how many repetitions are going to be needed to meet those criteria. To address this need JavaScript provides the while loop. In essence the while loop repeats a set of tasks until a specified condition is met.
Syntax:
while (''condition'')
{
      ''Statements''
}

    In that above syntax outline, condition is an expression that will return either true or false and JavaScript Statements represents the JavaScript to be executed while the expression is true. For example:

while ( i < 10 )
{
      i = i + j;
}

    In the above example, the while expression will evaluate whether i is less than 10. If it is already greater than 10 then the code in the braces is skipped and the loop exits without performing any tasks. If it is not greater than 10 the code in the braces is executed and the loop returns to the while statement and repeats the evaluation of i. This process repeats until i is greater than 10, at which point the loop exits

switch Statements: when a need arises to evaluate a large number of conditions. An easier way to handle such situations is to use the switch statement.
Syntax:
switch (''value'')
{
     case "''match1''" :
     ''statements''
     break;

     case "''match2''" :
     ''statements''
     break;

     case "''match3''" :
     ''statements''
     break;

     case "''match4''" :
     ''statements''
     break;

     case "''match5''" :
     ''statements''
     break;

     default :
     ''statements''
     break;
}
    There can be any number of case statements - basically as many as you need to fully compare the value in the switch statement against the possible options (represented by match1 through to match5 in the above example) specified by the case statements. When a match is found the statements corresponding to the matching case are executed. Note the break; statement. Without the break all the cases after the matching case will also be executed.

    The default statement specifies the action that should be taken if no match is found. The following provides an example of the switch statement in action:

Example: (in javascript)
var carModel = "Focus";

switch (carModel)
{
     case "Durango" :
     document.write ("Manufactured by Dodge");
     break;

     case "Camry" :
     document.write ("Manufactured by Toyota");
     break;

     case "Focus" :
     document.write ("Manufactured by Ford");
     break;

     case "320i" :
     document.write ("Manufactured by BMW");
     break;

     case "Civic" :
     document.write ("Manufactured by Honda");
     break;

     default  :
     document.write ("Unknown Car Model");
     break;
}

Breaking a Loop: Occasionally it is necessary to exit from a loop before it has met whatever completion criteria were specified. To achieve this, the break statement must be used. The following example contains a loop that uses the break statement to exit from the loop when i = 100, even though the loop is designed to iterate 1000 times:

for (i = 0; i < 1000; i++)
{
        if (i == 10) 
        {
             break;
        }
}

Skipping Statements in Current Loop Iteration: The break statement, when encountered in a loop breaks skips all remaining statements in the loop body and breaks the loop. The continue statement also skips all remaining statements in the loop for the current iteration, but returns to the top of the loop and allows it to continue running.
Share:

Declaring constants in C#

 Constants are fields whose values are set at compile time and can never be changed. Use constants to provide meaningful names instead of numeric literals for special values.
Note
    In C# the #define preprocessor directive cannot be used to define constants in the way that is typically used in C and C++.

    To define constant values of integral types (int, byte, and so on) use an enumerated type. For more information, see enum.

    To define non-integral constants, one approach is to group them in a single static class named Constants. This will require that all references to the constants be prefaced with the class name, as shown in the following example.

Example
static class Constants
{
    public const double Pi = 3.14159;
    public const int SpeedOfLight = 300000; // km per sec.
}
class Program
{
    static void Main()
    {
        double radius = 5.3;
        double area = Constants.Pi * (radius * radius);
        int secsFromSun = 149476000 / Constants.SpeedOfLight; // in km
    }
}
    The use of the class name qualifier helps ensure that you and others who use the constant understand that it is constant and cannot be modified.
Share:

Declaring variables in C#

 Variables declared this way within classes are called instance variables. They belong to an instance of the class.
Syntax
modifier dataType variableName; ///modifier is optional

///variables can be assigned values either separately or on declaration
variableName = value; ///separate line assignment

modifier dataType variableName = value; ///same line assignment

///implicitly typed variable
var variable2 = value;

Notes
The modifier (public, private) restricts or permits direct access to the variable with respect to its scope (class, method, etc.). Variables declared within a class are called fields.

Variables without a modifier are known as local variables, typically used within a method. They are temporary and only exist within the scope of the where its declared method.

dataType is the data type of the variable.

Example
public class Car { 
    private int speed; ///public variable declaration
    public int wheels; ///private variable declaration
    
    /*...constructor, etc...*/

    public void speedUp() {
        ///local variable declaration, in line assignment, only seen within speedUp method
        int speedIncrease = 10;
        speed += speedIncrease;
    }
}
Share:

Basic outline for learning a programming language:

 Basic outline for learning a programming language:
  - Requires about keywords when name variables, function
  - Operators
    + Mathematical operators: +, -, *, /, ++, --, \, %
    + Relational operators: ==, !=, >, <, >=, <=
    + Logical operators: &&, ||
    + Bitwise Operators: &, |
  - Data types; char, string, number ( byte, integer, long, float, double)
  - Declare and assign constant, variable, function, class
  - Control commands: if, for, while, switch, continue, break
Share:
Powered by Blogger.

Recent Posts

Pages