func (p *people) SetSal(sal float64){ if sal >= 3000&& sal<=30000{ p.sal = sal } else { fmt.Println("输入错误") } } 出错在哪
时间: 2024-05-20 12:15:00 浏览: 19
这个函数看起来是用来设置 People 结构体中的 sal 字段的。函数体中的语句是如果输入的 sal 大于等于 3000 并且小于等于 30000,就将 sal 赋值给 People 结构体中的 sal 字段,否则输出 "输入错误"。
目前没有看到明显的语法错误,但是需要注意以下几点:
1. 请确保 People 结构体中的 sal 字段是公开的(即首字母大写),否则该函数无法访问到 sal 字段。
2. 请确保该函数的接收者 people 是一个指针类型,否则该函数无法修改 People 结构体中的 sal 字段。
3. 请确保该函数被正确地调用,即使用正确的指针调用该函数。
如果以上三点都没有问题,那么该函数应该是没有问题的。可以提供更多信息,以便更好地排除问题。
相关问题
void func(char str[]){ while(*str) if(*str >= 'a' && *str <= 'z') *str++-= 32; }
这是一个函数,函数名为func,参数为一个字符数组str。这个函数的作用是将字符串中的小写字母转换成大写字母。具体实现是通过while循环遍历字符串中的每一个字符,然后判断是否为小写字母(即ASCII码值在97~122之间),如果是,则将其ASCII码值减去32,即转换成对应的大写字母。最后返回值为void,即没有返回值。
[AbpAuthorize("Attendance.User.GetAllUser")] public PagedOutPutDto<UserDto> GetAllUserAttendance(QueryModel input) { input.Paged.page = 1; input.Paged.MaxResultCount = int.MaxValue; var user = new PagedOutPut<User>(); if (input.Items.FirstOrDefault(i => i.Field == "TenDay") != null) { input.Items.RemoveAll(i => i.Field == "TenDay"); var parseResult = 0; Func<User, bool> predicate = i => { if (!int.TryParse(i.Probation, out parseResult) || (i.IsDimission ?? false)) { return false; } var endShiyong = i.EntryDate.AddMonths(int.Parse(i.Probation)); //试用期结束日期 if (endShiyong >= DateTime.Now && endShiyong <= DateTime.Now.AddDays(10)) { return true; } return false; }; user = _userRepository.GetAllList().Where(predicate).AsQueryable().Where(input); } else { user = _userRepository.GetAll().Where(input); } return new PagedOutPutDto<UserDto>() { Items = Mapper.Map<List<User>, List<UserDto>>(user.Items), TotalCount = user.TotalCount }; }
这是一段 C# 代码,使用了 AbpAuthorize 属性来限制访问权限。该方法名为 GetAllUserAttendance,接受一个 QueryModel 参数,并返回一个 PagedOutPutDto<UserDto> 对象。
在方法体内,首先对传入的 QueryModel 进行一些修改。将 input.Paged.page 设置为 1,将 input.Paged.MaxResultCount 设置为 int.MaxValue,这样可以获取所有的用户数据。
接下来,根据 input 中的查询条件来筛选用户数据。如果 input 中存在 Field 为 "TenDay" 的项,则移除该项,并创建一个名为 predicate 的 Func<User, bool> 条件委托。在条件委托中,首先判断用户的 Probation 字段是否可以转换为整数,并且用户没有离职。然后,计算试用期结束日期(EntryDate 加上 Probation 个月),判断是否在当前时间到当前时间加上 10 天之间。如果满足条件,则返回 true。最后使用该条件委托对 _userRepository 进行筛选得到 user 对象。
如果 input 中不存在 Field 为 "TenDay" 的项,则直接使用 _userRepository.GetAll().Where(input) 对象进行筛选得到 user 对象。
最后,将 user.Items 转换为 UserDto 对象列表,并返回一个 PagedOutPutDto<UserDto> 对象,其中包含转换后的列表和总记录数。
请注意,这段代码中使用了一些自定义的类和方法,比如 PagedOutPut、QueryModel、_userRepository 等。你可能需要根据实际情况进行适当的修改和调整。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)