找到 34423 篇文章,关于编程

C# 中的 DateTime.SpecifyKind() 方法

AmitDiwan
更新于 2019年11月7日 05:50:12

5K+ 次查看

C# 中的 DateTime.SpecifyKind() 方法用于创建一个新的 DateTime 对象,该对象与指定的 DateTime 具有相同的刻度数,但被指定为本地时间、协调世界时 (UTC) 或两者都不属于,这由指定的 DateTimeKind 值指示。语法以下是语法 -public static DateTime SpecifyKind (DateTime d, DateTimeKind kind);上面,参数 d 是 DateTime,而 kind 是指示新对象表示本地时间、UTC 或两者都不属于的枚举值之一。示例让我们现在来看一个实现 DateTime.SpecifyKind() 方法的示例 -using System; using System.Globalization; public class Demo {   ... 阅读更多

C# 中的 Decimal.ToUInt16() 方法

AmitDiwan
更新于 2019年11月7日 05:48:06

32 次查看

C# 中的 Decimal.ToUInt16() 方法用于将指定 Decimal 的值转换为等效的 16 位无符号整数。语法以下是语法 -public static ushort ToUInt16 (decimal val);上面,值 val 是要转换的十进制数。示例让我们现在来看一个实现 Decimal.ToUInt16() 方法的示例 -using System; public class Demo {    public static void Main(){       Decimal val = 875.647m;       Console.WriteLine("Decimal value = "+val);       ushort res = Decimal.ToUInt16(val);       Console.WriteLine("16 位无符号整数 = "+res);    } }输出这将产生以下输出 -Decimal value = ... 阅读更多

C# 中的 Math.BigMul() 方法

AmitDiwan
更新于 2019年11月7日 05:45:19

168 次查看

C# 中的 Math.BigMul() 方法用于计算两个 32 位数字的完整乘积。该方法返回一个包含这两个数字乘积的 Int64 整数。语法以下是语法 -public static long BigMul (int val1, int val2);这里,val1 是要乘以的第一个数字,而 val2 是第二个数字。示例让我们现在来看一个实现 Math.BigMul() 方法的示例 -using System; public class Demo {    public static void Main(){       int val1 = Int32.MaxValue;       int val2 = Int32.MaxValue;       Console.WriteLine("两个数字的乘积 = " + Math.BigMul(val1, val2));   ... 阅读更多

C# 中的 Math.Atan2() 方法

AmitDiwan
更新于 2019年11月7日 05:42:39

262 次查看

C# 中的 Math.Atan2() 方法用于返回正切值为两个指定数字的商的角度。语法以下是语法 -public static double Atan2 (double val1, double val2);上面,val1 是 y 坐标,而 val2 是 x 坐标。示例让我们现在来看一个实现 Math.Atan2() 方法的示例 -using System; public class Demo {    public static void Main(){       double val1 = 3.0;       double val2 = 1.0;       double angle, radians;       radians = Math.Atan2(val1, val2);       angle = radians * (180/Math.PI);       ... 阅读更多

C# 中的 Char.ToString() 方法

AmitDiwan
更新于 2019年11月7日 05:39:47

104 次查看

C# 中的 Char.ToString() 方法用于将此实例的值转换为其等效的字符串表示形式。语法以下是语法 -public override string ToString ();示例让我们现在来看一个实现 Char.ToString() 方法的示例 -using System; public class Demo {    public static void Main(){       char ch = 'p';       Console.WriteLine("Value = "+ch);       char res1 = Char.ToLowerInvariant(ch);       Console.WriteLine("小写等效项 = "+res1);       string res2 = ch.ToString();       Console.WriteLine("字符串等效项 = "+res2);    } }输出这将产生以下输出 -Value = p ... 阅读更多

在 Java 中使用 Jackson 的 @JsonView 注解的重要性?

raja
更新于 2020年7月8日 11:19:19

1K+ 次查看

JsonView 注解可用于在序列化和反序列化过程中动态地包含/排除属性。我们需要配置 ObjectMapper 类以包含用于使用 writerWithView() 方法从 Java 对象写入 JSON 的视图类型。语法@Target(value={ANNOTATION_TYPE, METHOD, FIELD}) @Retention(value=RUNTIME) public @interface JsonView示例import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonView; import com.fasterxml.jackson.core.JsonProcessingException; public class JsonViewAnnotationTest {    public static void main(String args[]) throws JsonProcessingException {       ObjectMapper objectMapper = new ObjectMapper();       String jsonString = objectMapper.writerWithView(Views.Public.class).writeValueAsString(new Person());       String jsonStringInternal = objectMapper.writerWithView(Views.Internal.class).writeValueAsString(new Person());       System.out.println(jsonString);       System.out.println(jsonStringInternal);    } } ... 阅读更多

如何在 Java 中使用排除过滤器将 Bean 转换为 JSON 对象?

raja
更新于 2020年7月8日 11:20:06

409 次查看

JsonConfig 类可用于配置序列化过程。我们可以使用 JsonConfig 的 setJsonPropertyFilter() 方法在序列化为 JSON 时设置属性过滤器。我们需要通过覆盖 PropertyFilter 接口的 apply() 方法来实现自定义 PropertyFilter 类。如果要过滤掉该属性,则返回 true,否则返回 false。语法public void setJsonPropertyFilter(PropertyFilter jsonPropertyFilter)示例import net.sf.json.JSONObject; import net.sf.json.JsonConfig; import net.sf.json.util.PropertyFilter; public class ConvertBeanToJsonExcludeFilterTest {    public static void main(String[] args) {       Student student = new Student("Sai", "Chaitanya", 20, "Hyderabad");       JsonConfig jsonConfig = new JsonConfig();       jsonConfig.setJsonPropertyFilter(new CustomPropertyFilter());       ... 阅读更多

如何在 Java 中使用 JSON-lib API 将 Bean 转换为不带类型提示的 XML?

raja
更新于 2020年7月8日 11:20:50

224 次查看

JSON-lib 是一个 Java 库,用于将 Java Bean、映射、数组和集合序列化和反序列化为 JSON 格式。我们可以使用 XMLSerializer 类的 setTypeHintsEnabled() 方法将 Bean 转换为不带类型提示的 XML,此方法设置是否可以将 JSON 类型包含为属性。我们可以将 false 作为参数传递给此方法以禁用 XML 中的类型提示。语法public void setTypeHintsEnabled(boolean typeHintsEnabled)示例import net.sf.json.JSONObject; import net.sf.json.xml.XMLSerializer; public class ConvertBeanToXMLNoHintsTest {    public static void main(String[] args) {       Employee emp = new Employee("Krishna Vamsi", 115, 30, "Java");       JSONObject jsonObj = JSONObject.fromObject(emp);     ... 阅读更多

C# 中的 Char.ToLowerInvariant(Char) 方法

AmitDiwan
更新于 2019年11月6日 08:06:14

82 次查看

C# 中的 Char.ToLowerInvariant() 方法用于使用不变文化的区分大小写规则将 Unicode 字符的值转换为其小写等效项。输出以下是语法 -public static char ToLowerInvariant (char ch);上面,参数 ch 是要转换的 Unicode 字符。示例让我们现在来看一个实现 Char.ToLowerInvariant() 方法的示例 -using System; public class Demo {    public static void Main(){       char ch = 'D';       char res = Char.ToLowerInvariant(ch);       Console.WriteLine("Value = "+ch);       Console.WriteLine("小写等效项 = "+res);    } }输出这将产生以下 ... 阅读更多

C# 中的 Char.Parse(String) 方法

AmitDiwan
更新于 2019年11月6日 08:04:37

4K+ 次查看

C# 中的 Char.Parse(String) 方法用于将指定字符串的值转换为其等效的 Unicode 字符。语法以下是语法:public static char Parse (string str);其中,字符串 str 是一个包含单个字符或 null 的字符串。示例现在让我们来看一个实现 Char.Parse(String) 方法的示例:using System; public class Demo {    public static void Main(){       string str ="a";       char res = Char.Parse(str);       Console.WriteLine("Value = "+str);       Console.WriteLine("Equivalent Unicode character = "+res);    } }输出这将产生以下输出:Value = ... 阅读更多

广告

© . All rights reserved.