# Kotlin 中缀函数调用 > 原文: [https://www.programiz.com/kotlin-programming/infix-notation](https://www.programiz.com/kotlin-programming/infix-notation) #### 在本文中,您将学习使用`int`表示法在 Kotlin 中调用函数(借助示例)。 在学习如何创建具有中缀表示法的函数之前,让我们探索两个常用的中缀函数。 当您使用`||`和`&&`操作时,编译器分别查找[或](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/or.html "Kotlin or function")和[和](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/and.html "Kotlin and function")函数,并在后台进行调用。 这两个功能支持中缀表示法。 * * * ### 示例:Kotlin `or`和`and`函数 ```kt fun main(args: Array) { val a = true val b = false var result: Boolean result = a or b // a.or(b) println("result = $result") result = a and b // a.and(b) println("result = $result") } ``` 运行该程序时,输出为: ```kt result = true result = false ``` 在上述程序中,使用`a or b`代替`a.or(b)`,并使用`a and b`代替`a.and(b)`。 这是可能的,因为这两个功能都支持中缀表示法。 * * * ### 如何创建带有中缀符号的函数? 您可以使用中缀符号在 Kotlin 中进行函数调用(如果该函数 * 是*成员函数*(或*扩展函数*)。 * 只有一个参数。 * 用`infix`关键字标记。 * * * ### 示例:带中缀符号的用户定义函数 ```kt class Structure() { infix fun createPyramid(rows: Int) { var k = 0 for (i in 1..rows) { k = 0 for (space in 1..rows-i) { print(" ") } while (k != 2*i-1) { print("* ") ++k } println() } } } fun main(args: Array) { val p = Structure() p createPyramid 4 // p.createPyramid(4) } ``` When you run the program, the output will be: ```kt * * * * * * * * * * * * * * * * ``` 在此,`createPyramid()`是创建金字塔结构的中缀函数。 它是类`Structure`的成员函数,仅接受类型为`Int`的一个参数,并以关键字`infix`开头。 吡喃酰胺的行数取决于传递给函数的参数。